Include config entry id in zwave_js signal names (#45282)
This commit is contained in:
parent
f1646f4ecc
commit
d7a0f1e467
8 changed files with 54 additions and 25 deletions
|
@ -66,12 +66,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
LOGGER.info("Connected to Zwave JS Server")
|
LOGGER.info("Connected to Zwave JS Server")
|
||||||
if initialized.is_set():
|
if initialized.is_set():
|
||||||
# update entity availability
|
# update entity availability
|
||||||
async_dispatcher_send(hass, f"{DOMAIN}_connection_state")
|
async_dispatcher_send(hass, f"{DOMAIN}_{entry.entry_id}_connection_state")
|
||||||
|
|
||||||
async def async_on_disconnect() -> None:
|
async def async_on_disconnect() -> None:
|
||||||
"""Handle websocket is disconnected."""
|
"""Handle websocket is disconnected."""
|
||||||
LOGGER.info("Disconnected from Zwave JS Server")
|
LOGGER.info("Disconnected from Zwave JS Server")
|
||||||
async_dispatcher_send(hass, f"{DOMAIN}_connection_state")
|
async_dispatcher_send(hass, f"{DOMAIN}_{entry.entry_id}_connection_state")
|
||||||
|
|
||||||
async def async_on_initialized() -> None:
|
async def async_on_initialized() -> None:
|
||||||
"""Handle initial full state received."""
|
"""Handle initial full state received."""
|
||||||
|
@ -89,7 +89,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
# run discovery on all node values and create/update entities
|
# run discovery on all node values and create/update entities
|
||||||
for disc_info in async_discover_values(node):
|
for disc_info in async_discover_values(node):
|
||||||
LOGGER.debug("Discovered entity: %s", disc_info)
|
LOGGER.debug("Discovered entity: %s", disc_info)
|
||||||
async_dispatcher_send(hass, f"{DOMAIN}_add_{disc_info.platform}", disc_info)
|
async_dispatcher_send(
|
||||||
|
hass, f"{DOMAIN}_{entry.entry_id}_add_{disc_info.platform}", disc_info
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_on_node_added(node: ZwaveNode) -> None:
|
def async_on_node_added(node: ZwaveNode) -> None:
|
||||||
|
|
|
@ -265,16 +265,18 @@ async def async_setup_entry(
|
||||||
entities: List[ZWaveBaseEntity] = []
|
entities: List[ZWaveBaseEntity] = []
|
||||||
|
|
||||||
if info.platform_hint == "notification":
|
if info.platform_hint == "notification":
|
||||||
entities.append(ZWaveNotificationBinarySensor(client, info))
|
entities.append(ZWaveNotificationBinarySensor(config_entry, client, info))
|
||||||
else:
|
else:
|
||||||
# boolean sensor
|
# boolean sensor
|
||||||
entities.append(ZWaveBooleanBinarySensor(client, info))
|
entities.append(ZWaveBooleanBinarySensor(config_entry, client, info))
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, f"{DOMAIN}_add_{BINARY_SENSOR_DOMAIN}", async_add_binary_sensor
|
hass,
|
||||||
|
f"{DOMAIN}_{config_entry.entry_id}_add_{BINARY_SENSOR_DOMAIN}",
|
||||||
|
async_add_binary_sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -308,9 +310,11 @@ class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
||||||
class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
||||||
"""Representation of a Z-Wave binary_sensor from Notification CommandClass."""
|
"""Representation of a Z-Wave binary_sensor from Notification CommandClass."""
|
||||||
|
|
||||||
def __init__(self, client: ZwaveClient, info: ZwaveDiscoveryInfo) -> None:
|
def __init__(
|
||||||
|
self, config_entry: ConfigEntry, client: ZwaveClient, info: ZwaveDiscoveryInfo
|
||||||
|
) -> None:
|
||||||
"""Initialize a ZWaveNotificationBinarySensor entity."""
|
"""Initialize a ZWaveNotificationBinarySensor entity."""
|
||||||
super().__init__(client, info)
|
super().__init__(config_entry, client, info)
|
||||||
# check if we have a custom mapping for this value
|
# check if we have a custom mapping for this value
|
||||||
self._mapping_info = self._get_sensor_mapping()
|
self._mapping_info = self._get_sensor_mapping()
|
||||||
|
|
||||||
|
|
|
@ -94,13 +94,15 @@ async def async_setup_entry(
|
||||||
def async_add_climate(info: ZwaveDiscoveryInfo) -> None:
|
def async_add_climate(info: ZwaveDiscoveryInfo) -> None:
|
||||||
"""Add Z-Wave Climate."""
|
"""Add Z-Wave Climate."""
|
||||||
entities: List[ZWaveBaseEntity] = []
|
entities: List[ZWaveBaseEntity] = []
|
||||||
entities.append(ZWaveClimate(client, info))
|
entities.append(ZWaveClimate(config_entry, client, info))
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, f"{DOMAIN}_add_{CLIMATE_DOMAIN}", async_add_climate
|
hass,
|
||||||
|
f"{DOMAIN}_{config_entry.entry_id}_add_{CLIMATE_DOMAIN}",
|
||||||
|
async_add_climate,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -108,9 +110,11 @@ async def async_setup_entry(
|
||||||
class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
||||||
"""Representation of a Z-Wave climate."""
|
"""Representation of a Z-Wave climate."""
|
||||||
|
|
||||||
def __init__(self, client: ZwaveClient, info: ZwaveDiscoveryInfo) -> None:
|
def __init__(
|
||||||
|
self, config_entry: ConfigEntry, client: ZwaveClient, info: ZwaveDiscoveryInfo
|
||||||
|
) -> None:
|
||||||
"""Initialize lock."""
|
"""Initialize lock."""
|
||||||
super().__init__(client, info)
|
super().__init__(config_entry, client, info)
|
||||||
self._hvac_modes: Dict[str, Optional[int]] = {}
|
self._hvac_modes: Dict[str, Optional[int]] = {}
|
||||||
self._hvac_presets: Dict[str, Optional[int]] = {}
|
self._hvac_presets: Dict[str, Optional[int]] = {}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from typing import Optional, Union
|
||||||
from zwave_js_server.client import Client as ZwaveClient
|
from zwave_js_server.client import Client as ZwaveClient
|
||||||
from zwave_js_server.model.value import Value as ZwaveValue, get_value_id
|
from zwave_js_server.model.value import Value as ZwaveValue, get_value_id
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
@ -21,8 +22,11 @@ EVENT_VALUE_UPDATED = "value updated"
|
||||||
class ZWaveBaseEntity(Entity):
|
class ZWaveBaseEntity(Entity):
|
||||||
"""Generic Entity Class for a Z-Wave Device."""
|
"""Generic Entity Class for a Z-Wave Device."""
|
||||||
|
|
||||||
def __init__(self, client: ZwaveClient, info: ZwaveDiscoveryInfo) -> None:
|
def __init__(
|
||||||
|
self, config_entry: ConfigEntry, client: ZwaveClient, info: ZwaveDiscoveryInfo
|
||||||
|
) -> None:
|
||||||
"""Initialize a generic Z-Wave device entity."""
|
"""Initialize a generic Z-Wave device entity."""
|
||||||
|
self.config_entry = config_entry
|
||||||
self.client = client
|
self.client = client
|
||||||
self.info = info
|
self.info = info
|
||||||
# entities requiring additional values, can add extra ids to this list
|
# entities requiring additional values, can add extra ids to this list
|
||||||
|
@ -42,9 +46,12 @@ class ZWaveBaseEntity(Entity):
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.info.node.on(EVENT_VALUE_UPDATED, self._value_changed)
|
self.info.node.on(EVENT_VALUE_UPDATED, self._value_changed)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass, f"{DOMAIN}_connection_state", self.async_write_ha_state
|
self.hass,
|
||||||
|
f"{DOMAIN}_{self.config_entry.entry_id}_connection_state",
|
||||||
|
self.async_write_ha_state,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,15 @@ async def async_setup_entry(
|
||||||
def async_add_light(info: ZwaveDiscoveryInfo) -> None:
|
def async_add_light(info: ZwaveDiscoveryInfo) -> None:
|
||||||
"""Add Z-Wave Light."""
|
"""Add Z-Wave Light."""
|
||||||
|
|
||||||
light = ZwaveLight(client, info)
|
light = ZwaveLight(config_entry, client, info)
|
||||||
async_add_entities([light])
|
async_add_entities([light])
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(hass, f"{DOMAIN}_add_{LIGHT_DOMAIN}", async_add_light)
|
async_dispatcher_connect(
|
||||||
|
hass,
|
||||||
|
f"{DOMAIN}_{config_entry.entry_id}_add_{LIGHT_DOMAIN}",
|
||||||
|
async_add_light,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,9 +66,11 @@ def byte_to_zwave_brightness(value: int) -> int:
|
||||||
class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||||
"""Representation of a Z-Wave light."""
|
"""Representation of a Z-Wave light."""
|
||||||
|
|
||||||
def __init__(self, client: ZwaveClient, info: ZwaveDiscoveryInfo) -> None:
|
def __init__(
|
||||||
|
self, config_entry: ConfigEntry, client: ZwaveClient, info: ZwaveDiscoveryInfo
|
||||||
|
) -> None:
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
super().__init__(client, info)
|
super().__init__(config_entry, client, info)
|
||||||
self._supports_color = False
|
self._supports_color = False
|
||||||
self._supports_white_value = False
|
self._supports_white_value = False
|
||||||
self._supports_color_temp = False
|
self._supports_color_temp = False
|
||||||
|
|
|
@ -45,12 +45,14 @@ async def async_setup_entry(
|
||||||
def async_add_lock(info: ZwaveDiscoveryInfo) -> None:
|
def async_add_lock(info: ZwaveDiscoveryInfo) -> None:
|
||||||
"""Add Z-Wave Lock."""
|
"""Add Z-Wave Lock."""
|
||||||
entities: List[ZWaveBaseEntity] = []
|
entities: List[ZWaveBaseEntity] = []
|
||||||
entities.append(ZWaveLock(client, info))
|
entities.append(ZWaveLock(config_entry, client, info))
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(hass, f"{DOMAIN}_add_{LOCK_DOMAIN}", async_add_lock)
|
async_dispatcher_connect(
|
||||||
|
hass, f"{DOMAIN}_{config_entry.entry_id}_add_{LOCK_DOMAIN}", async_add_lock
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ async def async_setup_entry(
|
||||||
entities: List[ZWaveBaseEntity] = []
|
entities: List[ZWaveBaseEntity] = []
|
||||||
|
|
||||||
if info.platform_hint == "string_sensor":
|
if info.platform_hint == "string_sensor":
|
||||||
entities.append(ZWaveStringSensor(client, info))
|
entities.append(ZWaveStringSensor(config_entry, client, info))
|
||||||
elif info.platform_hint == "numeric_sensor":
|
elif info.platform_hint == "numeric_sensor":
|
||||||
entities.append(ZWaveNumericSensor(client, info))
|
entities.append(ZWaveNumericSensor(config_entry, client, info))
|
||||||
else:
|
else:
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
"Sensor not implemented for %s/%s",
|
"Sensor not implemented for %s/%s",
|
||||||
|
@ -51,7 +51,9 @@ async def async_setup_entry(
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, f"{DOMAIN}_add_{SENSOR_DOMAIN}", async_add_sensor
|
hass,
|
||||||
|
f"{DOMAIN}_{config_entry.entry_id}_add_{SENSOR_DOMAIN}",
|
||||||
|
async_add_sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,15 @@ async def async_setup_entry(
|
||||||
def async_add_switch(info: ZwaveDiscoveryInfo) -> None:
|
def async_add_switch(info: ZwaveDiscoveryInfo) -> None:
|
||||||
"""Add Z-Wave Switch."""
|
"""Add Z-Wave Switch."""
|
||||||
entities: List[ZWaveBaseEntity] = []
|
entities: List[ZWaveBaseEntity] = []
|
||||||
entities.append(ZWaveSwitch(client, info))
|
entities.append(ZWaveSwitch(config_entry, client, info))
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
hass.data[DOMAIN][config_entry.entry_id][DATA_UNSUBSCRIBE].append(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, f"{DOMAIN}_add_{SWITCH_DOMAIN}", async_add_switch
|
hass,
|
||||||
|
f"{DOMAIN}_{config_entry.entry_id}_add_{SWITCH_DOMAIN}",
|
||||||
|
async_add_switch,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue