mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Improve naming of Hue entertainment area sensors
This commit is contained in:
@@ -76,6 +76,11 @@
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"entertainment_area": {
|
||||
"name": "Entertainment area {area_name}"
|
||||
}
|
||||
},
|
||||
"event": {
|
||||
"button": {
|
||||
"name": "Button {button_id}",
|
||||
|
||||
@@ -239,20 +239,36 @@ class HueEntertainmentActiveSensor(HueBaseEntity, BinarySensorEntity):
|
||||
resource: EntertainmentConfiguration
|
||||
|
||||
entity_description = BinarySensorEntityDescription(
|
||||
key="entertainment_active_sensor", device_class=BinarySensorDeviceClass.RUNNING
|
||||
key="entertainment_active_sensor",
|
||||
device_class=BinarySensorDeviceClass.RUNNING,
|
||||
has_entity_name=True,
|
||||
translation_key="entertainment_area",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bridge: HueBridge,
|
||||
controller: EntertainmentConfigurationController,
|
||||
resource: EntertainmentConfiguration,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(bridge, controller, resource)
|
||||
self._attr_translation_placeholders = {"area_name": resource.metadata.name}
|
||||
|
||||
@property
|
||||
@override
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self.resource.status == EntertainmentStatus.ACTIVE
|
||||
|
||||
@property
|
||||
@callback
|
||||
@override
|
||||
def name(self) -> str:
|
||||
"""Return sensor name."""
|
||||
return self.resource.metadata.name
|
||||
def on_update(self) -> None:
|
||||
"""Call on update event."""
|
||||
self._attr_translation_placeholders = {"area_name": self.resource.metadata.name}
|
||||
# the entity name is cached, invalidate it so a rename
|
||||
# of the entertainment area in the Hue app is picked up
|
||||
self.__dict__.pop("name", None)
|
||||
|
||||
|
||||
# pylint: disable-next=home-assistant-enforce-class-module
|
||||
|
||||
@@ -29,10 +29,12 @@ async def test_binary_sensors(
|
||||
assert sensor.attributes["device_class"] == "motion"
|
||||
|
||||
# test entertainment room active sensor
|
||||
sensor = hass.states.get("binary_sensor.philips_hue_entertainmentroom_1")
|
||||
sensor = hass.states.get(
|
||||
"binary_sensor.philips_hue_entertainment_area_entertainmentroom_1"
|
||||
)
|
||||
assert sensor is not None
|
||||
assert sensor.state == "off"
|
||||
assert sensor.name == "Philips hue Entertainmentroom 1"
|
||||
assert sensor.name == "Philips hue Entertainment area Entertainmentroom 1"
|
||||
assert sensor.attributes["device_class"] == "running"
|
||||
|
||||
# test contact sensor
|
||||
@@ -187,6 +189,46 @@ async def test_grouped_motion_sensor(
|
||||
assert sensor.state == "unknown"
|
||||
|
||||
|
||||
async def test_entertainment_active_sensor(
|
||||
hass: HomeAssistant, mock_bridge_v2: Mock, v2_resources_test_data: JsonArrayType
|
||||
) -> None:
|
||||
"""Test HueEntertainmentActiveSensor functionality."""
|
||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||
await setup_platform(hass, mock_bridge_v2, Platform.BINARY_SENSOR)
|
||||
|
||||
test_entity_id = "binary_sensor.philips_hue_entertainment_area_entertainmentroom_1"
|
||||
sensor = hass.states.get(test_entity_id)
|
||||
assert sensor is not None
|
||||
assert sensor.state == "off"
|
||||
|
||||
# test the sensor turns on once the entertainment area becomes active
|
||||
mock_bridge_v2.api.emit_event(
|
||||
"update",
|
||||
{
|
||||
"id": "c14cf1cf-6c7a-4984-b8bb-c5b71aeb70fc",
|
||||
"type": "entertainment_configuration",
|
||||
"status": "active",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(test_entity_id).state == "on"
|
||||
|
||||
# test the name follows a rename of the entertainment area in the Hue app
|
||||
mock_bridge_v2.api.emit_event(
|
||||
"update",
|
||||
{
|
||||
"id": "c14cf1cf-6c7a-4984-b8bb-c5b71aeb70fc",
|
||||
"type": "entertainment_configuration",
|
||||
"metadata": {"name": "Entertainmentroom 2"},
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (
|
||||
hass.states.get(test_entity_id).name
|
||||
== "Philips hue Entertainment area Entertainmentroom 2"
|
||||
)
|
||||
|
||||
|
||||
async def test_motion_aware_sensor(
|
||||
hass: HomeAssistant, mock_bridge_v2: Mock, v2_resources_test_data: JsonArrayType
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user