async def async_added_to_hass(self):
    'Register callbacks.'

    @callback
    def qr_state_listener(entity, old_state, new_state):
        'Handle device state changes.'
        self._refresh_()

    @callback
    def qr_sensor_startup(event):
        'Update template on startup.'
        async_track_state_change(self.hass, self._entities, qr_state_listener)
    self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, qr_sensor_startup)
Register callbacks.
async def async_added_to_hass(self):
    

    @callback
    def qr_state_listener(entity, old_state, new_state):
        'Handle device state changes.'
        self._refresh_()

    @callback
    def qr_sensor_startup(event):
        'Update template on startup.'
        async_track_state_change(self.hass, self._entities, qr_state_listener)
    self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, qr_sensor_startup)