Questions About My First Component

Hi all,

Just writing my first component and have a few questions about the code below:

1: hass.states.set(‘Test.Value’, ‘Yes’) doesn’t honour capitalisation in the state card, is there a way to force it? Should ‘hass.states.set’ be used to set something that will only be yes or no\true or false?

2: My component connects to an API that is only refreshed every hour, is it possible to force the polling interval via code and not relying on the user?

3: def update throws ‘TypeError: update() missing 1 required positional argument: ‘state’’ . . . when updating, it’s more than likely something small but I just can see it :slight_smile:

Any help would be awesome!!!

import logging

from homeassistant.helpers.entity import Entity
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD

LOGGER = logging.getLogger(__name__)

    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string

def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the platform."""
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)

    hass.states.set('Test.Value', 'Yes')

        TestSensor('Upload', '100', 'GB','mdi:upload'),
        TestSensor('Download', 78, 'KB','mdi:download')

    LOGGER.warning("Setup finished")

class TestSensor(Entity):
    """Representation of the Test Sensor."""

    def __init__(self, name, state, unit_of_measurement, icon):
        """Initialize the sensor."""
        self._name = name
        self._state = state
        self._unit_of_measurement = unit_of_measurement
        self._icon = icon

    def name(self):
        """Return the name of the sensor."""
        return self._name

    def state(self):
        """Return the state of the sensor."""
        return self._state

    def unit_of_measurement(self):
        """Return the unit of measurement."""
        return self._unit_of_measurement

    def icon(self):
       """Return the icon if any."""
       return self._icon

    def update(self, state):
        """Fetch new state data for the sensor.
        This is the only method that should fetch new data for Home Assistant.
        self._state = state