'Initialize the sensor.'

def __init__(self, hass, device_id, friendly_name, target_entity, attribute, device_class, invert):

    self._hass = hass
    self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
    self._name = friendly_name
    self._target_entity = target_entity
    self._attribute = attribute
    self._device_class = device_class
    self._invert = invert
    self._state = None
    self.from_state = None
    self.to_state = None
    @callback
    def trend_sensor_state_listener(entity, old_state, new_state):
        'Handle    the    target    device    state    changes.'
        self.from_state = old_state
        self.to_state = new_state
        hass.async_add_job(self.async_update_ha_state(True))
    track_state_change(hass, target_entity, trend_sensor_state_listener)
