Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zha ZCL AnalogOutput cluster support #30211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions homeassistant/components/input_number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _cv_input_number(cfg):
)
)
},
required=True,
required=False,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
Expand All @@ -115,7 +115,7 @@ def _cv_input_number(cfg):

async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
"""Set up an input slider."""
component = EntityComponent(_LOGGER, DOMAIN, hass)
component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)
id_manager = collection.IDManager()

yaml_collection = collection.YamlCollection(
Expand All @@ -134,9 +134,10 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
component, storage_collection, InputNumber
)

await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in config[DOMAIN].items()]
)
if DOMAIN in config:
await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in config[DOMAIN].items()]
)
await storage_collection.async_load()

collection.StorageCollectionWebsocket(
Expand Down Expand Up @@ -207,6 +208,16 @@ async def _update_data(self, data: dict, update_data: typing.Dict) -> typing.Dic
return _cv_input_number({**data, **update_data})


async def async_setup_entry(hass, entry):
"""Set up a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry)


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)


class InputNumber(RestoreEntity):
"""Representation of a slider."""

Expand Down Expand Up @@ -288,7 +299,10 @@ async def async_added_to_hass(self):
return

state = await self.async_get_last_state()
value = state and float(state.state)
try:
value = state and float(state.state)
except ValueError:
value = None

# Check against None because value can be 0
if value is not None and self._minimum <= value <= self._maximum:
Expand Down
14 changes: 13 additions & 1 deletion homeassistant/components/zha/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from homeassistant.components.cover import DOMAIN as COVER
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER
from homeassistant.components.fan import DOMAIN as FAN
from homeassistant.components.input_number import DOMAIN as INPUT_NUMBER
from homeassistant.components.light import DOMAIN as LIGHT
from homeassistant.components.lock import DOMAIN as LOCK
from homeassistant.components.sensor import DOMAIN as SENSOR
Expand Down Expand Up @@ -46,6 +47,7 @@
BINDINGS = "bindings"

CHANNEL_ACCELEROMETER = "accelerometer"
CHANNEL_ANALOG_OUTPUT = "analog_output"
CHANNEL_ATTRIBUTE = "attribute"
CHANNEL_BASIC = "basic"
CHANNEL_COLOR = "light_color"
Expand Down Expand Up @@ -73,7 +75,17 @@
CLUSTER_TYPE_IN = "in"
CLUSTER_TYPE_OUT = "out"

COMPONENTS = (BINARY_SENSOR, COVER, DEVICE_TRACKER, FAN, LIGHT, LOCK, SENSOR, SWITCH)
COMPONENTS = (
BINARY_SENSOR,
COVER,
DEVICE_TRACKER,
FAN,
INPUT_NUMBER,
LIGHT,
LOCK,
SENSOR,
SWITCH,
)

CONF_BAUDRATE = "baudrate"
CONF_DATABASE = "database_path"
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/zha/core/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from homeassistant.components.cover import DOMAIN as COVER
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER
from homeassistant.components.fan import DOMAIN as FAN
from homeassistant.components.input_number import DOMAIN as INPUT_NUMBER
from homeassistant.components.light import DOMAIN as LIGHT
from homeassistant.components.lock import DOMAIN as LOCK
from homeassistant.components.sensor import DOMAIN as SENSOR
Expand Down Expand Up @@ -66,6 +67,7 @@
zcl.clusters.closures.DoorLock: LOCK,
zcl.clusters.closures.WindowCovering: COVER,
zcl.clusters.general.AnalogInput.cluster_id: SENSOR,
zcl.clusters.general.AnalogOutput.cluster_id: INPUT_NUMBER,
zcl.clusters.general.MultistateInput.cluster_id: SENSOR,
zcl.clusters.general.OnOff: SWITCH,
zcl.clusters.general.PowerConfiguration: SENSOR,
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/zha/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, unique_id, zha_device, channels, skip_entity_id=False, **kwar
self._unsubs = []
self.remove_future = None
for channel in channels:
_LOGGER.debug(channel.name)
self.cluster_channels[channel.name] = channel

@property
Expand Down