mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use platform tag to register components on hue SensorManager (#32732)
* Use platform tag to register components on hue SensorManager instead of a boolean flag to decide between sensor and binary sensor, so it could be used externally (or to get ready for inclusion of other comps) * Make new item discovery platform agnostic for SensorManager
This commit is contained in:
parent
11a25157c1
commit
94b6ab2862
@ -17,7 +17,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Defer binary sensor setup to the shared sensor module."""
|
||||
await hass.data[HUE_DOMAIN][
|
||||
config_entry.entry_id
|
||||
].sensor_manager.async_register_component(True, async_add_entities)
|
||||
].sensor_manager.async_register_component("binary_sensor", async_add_entities)
|
||||
|
||||
|
||||
class HuePresence(GenericZLLSensor, BinarySensorDevice):
|
||||
@ -44,7 +44,7 @@ class HuePresence(GenericZLLSensor, BinarySensorDevice):
|
||||
SENSOR_CONFIG_MAP.update(
|
||||
{
|
||||
TYPE_ZLL_PRESENCE: {
|
||||
"binary": True,
|
||||
"platform": "binary_sensor",
|
||||
"name_format": PRESENCE_NAME_FORMAT,
|
||||
"class": HuePresence,
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Defer sensor setup to the shared sensor module."""
|
||||
await hass.data[HUE_DOMAIN][
|
||||
config_entry.entry_id
|
||||
].sensor_manager.async_register_component(False, async_add_entities)
|
||||
].sensor_manager.async_register_component("sensor", async_add_entities)
|
||||
|
||||
|
||||
class GenericHueGaugeSensorEntity(GenericZLLSensor, Entity):
|
||||
@ -82,12 +82,12 @@ class HueTemperature(GenericHueGaugeSensorEntity):
|
||||
SENSOR_CONFIG_MAP.update(
|
||||
{
|
||||
TYPE_ZLL_LIGHTLEVEL: {
|
||||
"binary": False,
|
||||
"platform": "sensor",
|
||||
"name_format": LIGHT_LEVEL_NAME_FORMAT,
|
||||
"class": HueLightLevel,
|
||||
},
|
||||
TYPE_ZLL_TEMPERATURE: {
|
||||
"binary": False,
|
||||
"platform": "sensor",
|
||||
"name_format": TEMPERATURE_NAME_FORMAT,
|
||||
"class": HueTemperature,
|
||||
},
|
||||
|
@ -62,9 +62,9 @@ class SensorManager:
|
||||
except AiohueException as err:
|
||||
raise UpdateFailed(f"Hue error: {err}")
|
||||
|
||||
async def async_register_component(self, binary, async_add_entities):
|
||||
async def async_register_component(self, platform, async_add_entities):
|
||||
"""Register async_add_entities methods for components."""
|
||||
self._component_add_entities[binary] = async_add_entities
|
||||
self._component_add_entities[platform] = async_add_entities
|
||||
|
||||
if len(self._component_add_entities) < 2:
|
||||
return
|
||||
@ -84,8 +84,7 @@ class SensorManager:
|
||||
if len(self._component_add_entities) < 2:
|
||||
return
|
||||
|
||||
new_sensors = []
|
||||
new_binary_sensors = []
|
||||
to_add = {}
|
||||
primary_sensor_devices = {}
|
||||
current = self.current
|
||||
|
||||
@ -129,10 +128,10 @@ class SensorManager:
|
||||
current[api[item_id].uniqueid] = sensor_config["class"](
|
||||
api[item_id], name, self.bridge, primary_sensor=primary_sensor
|
||||
)
|
||||
if sensor_config["binary"]:
|
||||
new_binary_sensors.append(current[api[item_id].uniqueid])
|
||||
else:
|
||||
new_sensors.append(current[api[item_id].uniqueid])
|
||||
|
||||
to_add.setdefault(sensor_config["platform"], []).append(
|
||||
current[api[item_id].uniqueid]
|
||||
)
|
||||
|
||||
self.bridge.hass.async_create_task(
|
||||
remove_devices(
|
||||
@ -140,10 +139,8 @@ class SensorManager:
|
||||
)
|
||||
)
|
||||
|
||||
if new_sensors:
|
||||
self._component_add_entities[False](new_sensors)
|
||||
if new_binary_sensors:
|
||||
self._component_add_entities[True](new_binary_sensors)
|
||||
for platform in to_add:
|
||||
self._component_add_entities[platform](to_add[platform])
|
||||
|
||||
|
||||
class GenericHueSensor(entity.Entity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user