diff --git a/homeassistant/components/konnected/__init__.py b/homeassistant/components/konnected/__init__.py index 7ed4d5c1ac6..db1e20204cd 100644 --- a/homeassistant/components/konnected/__init__.py +++ b/homeassistant/components/konnected/__init__.py @@ -360,8 +360,14 @@ class KonnectedView(HomeAssistantView): try: zone_num = str(payload.get(CONF_ZONE) or PIN_TO_ZONE[payload[CONF_PIN]]) payload[CONF_ZONE] = zone_num - zone_data = device[CONF_BINARY_SENSORS].get(zone_num) or next( - (s for s in device[CONF_SENSORS] if s[CONF_ZONE] == zone_num), None + zone_data = ( + device[CONF_BINARY_SENSORS].get(zone_num) + or next( + (s for s in device[CONF_SWITCHES] if s[CONF_ZONE] == zone_num), None + ) + or next( + (s for s in device[CONF_SENSORS] if s[CONF_ZONE] == zone_num), None + ) ) except KeyError: zone_data = None diff --git a/homeassistant/components/konnected/handlers.py b/homeassistant/components/konnected/handlers.py index 923e5d63899..879d0d4cf8f 100644 --- a/homeassistant/components/konnected/handlers.py +++ b/homeassistant/components/konnected/handlers.py @@ -18,7 +18,7 @@ HANDLERS = decorator.Registry() @HANDLERS.register("state") async def async_handle_state_update(hass, context, msg): - """Handle a binary sensor state update.""" + """Handle a binary sensor or switch state update.""" _LOGGER.debug("[state handler] context: %s msg: %s", context, msg) entity_id = context.get(ATTR_ENTITY_ID) state = bool(int(msg.get(ATTR_STATE))) diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index b599fe55242..9c9f8193dcd 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -9,6 +9,8 @@ from homeassistant.const import ( CONF_SWITCHES, CONF_ZONE, ) +from homeassistant.core import callback +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import ToggleEntity from .const import ( @@ -130,6 +132,16 @@ class KonnectedSwitch(ToggleEntity): state, ) + @callback + def async_set_state(self, state): + """Update the switch state.""" + self._set_state(state) + async def async_added_to_hass(self): - """Store entity_id.""" + """Store entity_id and register state change callback.""" self._data["entity_id"] = self.entity_id + self.async_on_remove( + async_dispatcher_connect( + self.hass, f"konnected.{self.entity_id}.update", self.async_set_state + ) + )