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:
Glenn Waters
2020-05-11 23:34:31 -04:00
committed by GitHub
parent b1d59679e5
commit ea9c103fe1
5 changed files with 37 additions and 5 deletions

View File

@ -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

View File

@ -4,13 +4,17 @@ import voluptuous as vol
import homeassistant.helpers.config_validation as cv
CONF_NETWORK = "network"
DOMAIN = "upb"
ATTR_ADDRESS = "address"
ATTR_BLINK_RATE = "blink_rate"
ATTR_BRIGHTNESS = "brightness"
ATTR_BRIGHTNESS_PCT = "brightness_pct"
ATTR_COMMAND = "command"
ATTR_RATE = "rate"
CONF_NETWORK = "network"
EVENT_UPB_LINK_CHANGED = "upb.link_changed"
VALID_BRIGHTNESS = vol.All(vol.Coerce(int), vol.Clamp(min=0, max=255))
VALID_BRIGHTNESS_PCT = vol.All(vol.Coerce(float), vol.Range(min=0, max=100))
VALID_RATE = vol.All(vol.Coerce(float), vol.Clamp(min=-1, max=3600))

View File

@ -2,7 +2,7 @@
"domain": "upb",
"name": "Universal Powerline Bus (UPB)",
"documentation": "https://www.home-assistant.io/integrations/upb",
"requirements": ["upb_lib==0.4.10"],
"requirements": ["upb_lib==0.4.11"],
"codeowners": ["@gwww"],
"config_flow": true
}

View File

@ -2114,7 +2114,7 @@ uEagle==0.0.1
unifiled==0.11
# homeassistant.components.upb
upb_lib==0.4.10
upb_lib==0.4.11
# homeassistant.components.upcloud
upcloud-api==0.4.5

View File

@ -844,7 +844,7 @@ twentemilieu==0.3.0
twilio==6.32.0
# homeassistant.components.upb
upb_lib==0.4.10
upb_lib==0.4.11
# homeassistant.components.huawei_lte
url-normalize==1.4.1