Universal Powerline Bus -- Link Events (#35526)
* Universal Powerline Bus - Link Event * Bump lib version. * Update homeassistant/components/upb/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
1 parent
b1d59679e5
commit
ea9c103fe1
5 files changed
+37
-5
No files matched your search
@@ -8,7 +8,14 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import (
|
||||
ATTR_ADDRESS,
|
||||
ATTR_BRIGHTNESS_PCT,
|
||||
ATTR_COMMAND,
|
||||
ATTR_RATE,
|
||||
DOMAIN,
|
||||
EVENT_UPB_LINK_CHANGED,
|
||||
)
|
||||
|
||||
UPB_PLATFORMS = ["light", "scene"]
|
||||
|
||||
@@ -34,6 +41,27 @@ async def async_setup_entry(hass, config_entry):
|
||||
hass.config_entries.async_forward_entry_setup(config_entry, component)
|
||||
)
|
||||
|
||||
def _element_changed(element, changeset):
|
||||
change = changeset.get("last_change")
|
||||
if change is None:
|
||||
return
|
||||
if change.get("command") is None:
|
||||
return
|
||||
|
||||
hass.bus.async_fire(
|
||||
EVENT_UPB_LINK_CHANGED,
|
||||
{
|
||||
ATTR_COMMAND: change["command"],
|
||||
ATTR_ADDRESS: element.addr.index,
|
||||
ATTR_BRIGHTNESS_PCT: change.get("level", -1),
|
||||
ATTR_RATE: change.get("rate", -1),
|
||||
},
|
||||
)
|
||||
|
||||
for link in upb.links:
|
||||
element = upb.links[link]
|
||||
element.add_callback(_element_changed)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user