Adopt Hue integration to latest changes in Hue firmware (#101001)

This commit is contained in:
Marcel van der Veldt 2023-09-27 23:36:12 +02:00 committed by GitHub
parent 7d07694496
commit b569cb61e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 216 additions and 29 deletions

View file

@ -2221,5 +2221,113 @@
"id": "52612630-841e-4d39-9763-60346a0da759",
"is_configured": true,
"type": "geolocation"
},
{
"id": "0240be0e-8b79-4a53-b9bb-b17fa14d7e75",
"product_data": {
"model_id": "SOC001",
"manufacturer_name": "Signify Netherlands B.V.",
"product_name": "Hue secure contact sensor",
"product_archetype": "unknown_archetype",
"certified": true,
"software_version": "2.67.9",
"hardware_platform_type": "100b-125"
},
"metadata": {
"name": "Test contact sensor",
"archetype": "unknown_archetype"
},
"identify": {},
"services": [
{
"rid": "18802b4a-b2f6-45dc-8813-99cde47f3a4a",
"rtype": "contact"
},
{
"rid": "d7fcfab0-69e1-4afb-99df-6ed505211db4",
"rtype": "tamper"
}
],
"type": "device"
},
{
"id": "18802b4a-b2f6-45dc-8813-99cde47f3a4a",
"owner": {
"rid": "0240be0e-8b79-4a53-b9bb-b17fa14d7e75",
"rtype": "device"
},
"enabled": true,
"contact_report": {
"changed": "2023-09-27T10:01:36.968Z",
"state": "contact"
},
"type": "contact"
},
{
"id": "d7fcfab0-69e1-4afb-99df-6ed505211db4",
"owner": {
"rid": "0240be0e-8b79-4a53-b9bb-b17fa14d7e75",
"rtype": "device"
},
"tamper_reports": [
{
"changed": "2023-09-25T10:02:08.774Z",
"source": "battery_door",
"state": "not_tampered"
}
],
"type": "tamper"
},
{
"id": "1cbda90c-b675-46b0-9e97-278e7e7857ed",
"id_v1": "/sensors/249",
"product_data": {
"model_id": "CAMERA",
"manufacturer_name": "Signify Netherlands B.V.",
"product_name": "Fake Hue Test Camera",
"product_archetype": "unknown_archetype",
"certified": true,
"software_version": "0.0.0",
"hardware_platform_type": "0"
},
"metadata": {
"name": "Test Camera",
"archetype": "unknown_archetype"
},
"identify": {},
"usertest": {
"status": "set",
"usertest": false
},
"services": [
{
"rid": "d9f2cfee-5879-426b-aa1f-553af8f38176",
"rtype": "camera_motion"
}
],
"type": "device"
},
{
"id": "d9f2cfee-5879-426b-aa1f-553af8f38176",
"id_v1": "/sensors/249",
"owner": {
"rid": "1cbda90c-b675-46b0-9e97-278e7e7857ed",
"rtype": "device"
},
"enabled": true,
"motion": {
"motion": true,
"motion_valid": true,
"motion_report": {
"changed": "2023-09-27T10:06:41.822Z",
"motion": true
}
},
"sensitivity": {
"status": "set",
"sensitivity": 2,
"sensitivity_max": 4
},
"type": "motion"
}
]

View file

@ -14,8 +14,8 @@ async def test_binary_sensors(
await setup_platform(hass, mock_bridge_v2, "binary_sensor")
# there shouldn't have been any requests at this point
assert len(mock_bridge_v2.mock_requests) == 0
# 2 binary_sensors should be created from test data
assert len(hass.states.async_all()) == 2
# 5 binary_sensors should be created from test data
assert len(hass.states.async_all()) == 5
# test motion sensor
sensor = hass.states.get("binary_sensor.hue_motion_sensor_motion")
@ -23,7 +23,6 @@ async def test_binary_sensors(
assert sensor.state == "off"
assert sensor.name == "Hue motion sensor Motion"
assert sensor.attributes["device_class"] == "motion"
assert sensor.attributes["motion_valid"] is True
# test entertainment room active sensor
sensor = hass.states.get(
@ -34,6 +33,51 @@ async def test_binary_sensors(
assert sensor.name == "Entertainmentroom 1: Entertainment Configuration"
assert sensor.attributes["device_class"] == "running"
# test contact sensor
sensor = hass.states.get("binary_sensor.test_contact_sensor_contact")
assert sensor is not None
assert sensor.state == "off"
assert sensor.name == "Test contact sensor Contact"
assert sensor.attributes["device_class"] == "opening"
# test contact sensor disabled == state unknown
mock_bridge_v2.api.emit_event(
"update",
{
"enabled": False,
"id": "18802b4a-b2f6-45dc-8813-99cde47f3a4a",
"type": "contact",
},
)
await hass.async_block_till_done()
sensor = hass.states.get("binary_sensor.test_contact_sensor_contact")
assert sensor.state == "unknown"
# test tamper sensor
sensor = hass.states.get("binary_sensor.test_contact_sensor_tamper")
assert sensor is not None
assert sensor.state == "off"
assert sensor.name == "Test contact sensor Tamper"
assert sensor.attributes["device_class"] == "tamper"
# test tamper sensor when no tamper reports exist
mock_bridge_v2.api.emit_event(
"update",
{
"id": "d7fcfab0-69e1-4afb-99df-6ed505211db4",
"tamper_reports": [],
"type": "tamper",
},
)
await hass.async_block_till_done()
sensor = hass.states.get("binary_sensor.test_contact_sensor_tamper")
assert sensor.state == "off"
# test camera_motion sensor
sensor = hass.states.get("binary_sensor.test_camera_motion")
assert sensor is not None
assert sensor.state == "on"
assert sensor.name == "Test Camera Motion"
assert sensor.attributes["device_class"] == "motion"
async def test_binary_sensor_add_update(hass: HomeAssistant, mock_bridge_v2) -> None:
"""Test if binary_sensor get added/updated from events."""

View file

@ -28,7 +28,6 @@ async def test_sensors(
assert sensor.attributes["device_class"] == "temperature"
assert sensor.attributes["state_class"] == "measurement"
assert sensor.attributes["unit_of_measurement"] == "°C"
assert sensor.attributes["temperature_valid"] is True
# test illuminance sensor
sensor = hass.states.get("sensor.hue_motion_sensor_illuminance")
@ -39,7 +38,6 @@ async def test_sensors(
assert sensor.attributes["state_class"] == "measurement"
assert sensor.attributes["unit_of_measurement"] == "lx"
assert sensor.attributes["light_level"] == 18027
assert sensor.attributes["light_level_valid"] is True
# test battery sensor
sensor = hass.states.get("sensor.wall_switch_with_2_controls_battery")

View file

@ -14,8 +14,8 @@ async def test_switch(
await setup_platform(hass, mock_bridge_v2, "switch")
# there shouldn't have been any requests at this point
assert len(mock_bridge_v2.mock_requests) == 0
# 2 entities should be created from test data
assert len(hass.states.async_all()) == 2
# 3 entities should be created from test data
assert len(hass.states.async_all()) == 3
# test config switch to enable/disable motion sensor
test_entity = hass.states.get("switch.hue_motion_sensor_motion")