Skip to content

Commit

Permalink
2.2b3
Browse files Browse the repository at this point in the history
* raise scene notifications from controller as HA events
  • Loading branch information
dgtal1 committed Oct 4, 2022
1 parent e9237b9 commit fa56c26
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
Binary file added extalife.zip
Binary file not shown.
1 change: 1 addition & 0 deletions extalife/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

CONF_EXTALIFE_EVENT_BASE = f"{DOMAIN}"
CONF_EXTALIFE_EVENT_TRANSMITTER = f"{CONF_EXTALIFE_EVENT_BASE}_transmitter"
CONF_EXTALIFE_EVENT_SCENE = f"{CONF_EXTALIFE_EVENT_BASE}_scene"

CONF_PROCESSOR_EVENT_STAT_NOTIFICATION = "notification"
CONF_PROCESSOR_EVENT_UNKNOWN = "unknown"
Expand Down
22 changes: 20 additions & 2 deletions extalife/helpers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EVENT_HOMEASSISTANT_STOP

from .const import DATA_CORE, DOMAIN
from .const import DATA_CORE, DOMAIN, CONF_EXTALIFE_EVENT_SCENE
from ..pyextalife import ExtaLifeAPI
from .typing import (
TransmitterManagerType,
Expand All @@ -22,6 +22,11 @@
from .services import ExtaLifeServices


MAP_NOTIF_CMD_TO_EVENT = {
ExtaLifeAPI.CMD_ACTIVATE_SCENE: CONF_EXTALIFE_EVENT_SCENE
}


_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -198,7 +203,13 @@ def _on_disconnect_callback(self):
def _on_status_notification_callback(self, msg):
if self._is_unloading or self._is_stopping:
return
self._data_manager.on_notify(msg)

# forward only state notifications to data manager to update channels
if msg.get("command") == self.api.CMD_CONTROL_DEVICE:
self._data_manager.on_notify(msg)

self._put_notification_on_event_bus(msg)


async def _periodic_reconnect_callback(self, now):
"""Reconnect with the controller after connection is lost
Expand All @@ -217,6 +228,13 @@ def controller_entity_added_to_hass(self, entity):
entity - Entity object"""
self._controller_entity = entity

def _put_notification_on_event_bus(self, msg):
""" This method raises a notification on HA Event Bus """
data = msg.get("data")
event = MAP_NOTIF_CMD_TO_EVENT.get(msg.get("command"))
if event:
self._hass.bus.async_fire(event, event_data=data)

@property
def api(self) -> ExtaLifeAPI:
return self._api
Expand Down
2 changes: 1 addition & 1 deletion extalife/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "extalife",
"name": "Exta Life",
"version": "2.2b2",
"version": "2.2b3",
"config_flow": true,
"documentation": "https://www.forumextalife.pl/index.php/board,56.0.html",
"requirements": [
Expand Down
3 changes: 2 additions & 1 deletion extalife/pyextalife.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class ExtaLifeAPI:
CMD_FETCH_RECEIVERS = 37
CMD_FETCH_SENSORS = 38
CMD_FETCH_TRANSMITTERS = 39
CMD_ACTIVATE_SCENE = 44
CMD_FETCH_NETW_SETTINGS = 102
CMD_FETCH_EXTAFREE = 203
CMD_VERSION = 151
Expand Down Expand Up @@ -388,7 +389,7 @@ async def _async_on_tcp_disconnect_callback(self):

async def _async_on_notification_callback(self, data):
""" Called when notification from the controller is received """
if self._on_notification_callback(data) is not None and data.get("command") == self.CMD_CONTROL_DEVICE:
if self._on_notification_callback(data) is not None:
# forward only device status changes to the listener
self._on_notification_callback(data)

Expand Down

0 comments on commit fa56c26

Please sign in to comment.