elric91 / homeassistant_zigate

Custom components for Home Assistant
MIT License
22 stars 5 forks source link

Raw zigate events #3

Open SaWey opened 6 years ago

SaWey commented 6 years ago

When using the switches, it sometimes takes a lot of time (+10s) before an action is taken.

I currenlty added the raw event stream to be able to use the switches faster.

self.hass.bus.fire('{}_{}'.format(addrep, property_id), {'value' : property_data})

in zigate2hass.py:

    def set_device_property(self, addr, endpoint, property_id, property_data):
        # decoding the address to assign the proper signal (bytes --> str)
        if endpoint:
            addrep = ZGT_SIGNAL_UPDATE.format(addr.decode() + endpoint.decode())
        else:
            addrep = ZGT_SIGNAL_UPDATE.format(addr.decode())

        _LOGGER.debug('ZIGATE SIGNAL :')
        _LOGGER.debug('- Signal   : {}'.format(addrep))
        _LOGGER.debug('- Property : {}'.format(property_id))
        _LOGGER.debug('- Data     : {}'.format(property_data))

        self.hass.bus.fire('{}_{}'.format(addrep, property_id), {'value' : property_data})
        dispatcher_send(self.hass, addrep, property_id, property_data)

This allows me to add automations directly based on the events:

- alias: 'Button clicked 3 times'
  trigger:
    platform: event
    event_type: zgt_signal_update_189f01_state
    event_data:
      value: multi_3
  action: 
    service: switch.toggle
    entity_id: switch.location_name
elric91 commented 6 years ago

Interesting. It may be interesting to replace the dispatcher_send / dispatcher_connect with hass.bus.listen & hass.bus.fire Need to check it into detail ... I'll keep you posted

max5962 commented 6 years ago

@elric91 & @SaWey Have you notice improvement using bus capability instead of dispatcher ?