From 5cb4bbd9067b5538552f73ca0b963e4976fa6666 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 26 Jul 2022 04:17:28 -1000 Subject: [PATCH] Fix min and max mireds with HKC (#75744) --- .../components/homekit_controller/light.py | 12 + .../homekit_controller/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../fixtures/nanoleaf_strip_nl55.json | 354 ++++++++++++++++++ .../test_nanoleaf_strip_nl55.py | 55 +++ 6 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 tests/components/homekit_controller/fixtures/nanoleaf_strip_nl55.json create mode 100644 tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py diff --git a/homeassistant/components/homekit_controller/light.py b/homeassistant/components/homekit_controller/light.py index 4073c1ac9fe..df691ac3f6f 100644 --- a/homeassistant/components/homekit_controller/light.py +++ b/homeassistant/components/homekit_controller/light.py @@ -71,6 +71,18 @@ class HomeKitLight(HomeKitEntity, LightEntity): self.service.value(CharacteristicsTypes.SATURATION), ) + @property + def min_mireds(self) -> int: + """Return minimum supported color temperature.""" + min_value = self.service[CharacteristicsTypes.COLOR_TEMPERATURE].minValue + return int(min_value) if min_value else super().min_mireds + + @property + def max_mireds(self) -> int: + """Return the maximum color temperature.""" + max_value = self.service[CharacteristicsTypes.COLOR_TEMPERATURE].maxValue + return int(max_value) if max_value else super().max_mireds + @property def color_temp(self) -> int: """Return the color temperature.""" diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index 51d753f77fc..2de2a915d41 100644 --- a/homeassistant/components/homekit_controller/manifest.json +++ b/homeassistant/components/homekit_controller/manifest.json @@ -3,7 +3,7 @@ "name": "HomeKit Controller", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/homekit_controller", - "requirements": ["aiohomekit==1.2.0"], + "requirements": ["aiohomekit==1.2.2"], "zeroconf": ["_hap._tcp.local.", "_hap._udp.local."], "bluetooth": [{ "manufacturer_id": 76, "manufacturer_data_start": [6] }], "dependencies": ["bluetooth", "zeroconf"], diff --git a/requirements_all.txt b/requirements_all.txt index 47afd92827c..bbf8e44cc80 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -168,7 +168,7 @@ aioguardian==2022.07.0 aioharmony==0.2.9 # homeassistant.components.homekit_controller -aiohomekit==1.2.0 +aiohomekit==1.2.2 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 32d8b2bf514..b383bce296f 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -152,7 +152,7 @@ aioguardian==2022.07.0 aioharmony==0.2.9 # homeassistant.components.homekit_controller -aiohomekit==1.2.0 +aiohomekit==1.2.2 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/tests/components/homekit_controller/fixtures/nanoleaf_strip_nl55.json b/tests/components/homekit_controller/fixtures/nanoleaf_strip_nl55.json new file mode 100644 index 00000000000..142af6c03a2 --- /dev/null +++ b/tests/components/homekit_controller/fixtures/nanoleaf_strip_nl55.json @@ -0,0 +1,354 @@ +[ + { + "aid": 1, + "services": [ + { + "iid": 1, + "type": "0000003E-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "00000014-0000-1000-8000-0026BB765291", + "iid": 2, + "perms": ["pw"], + "format": "bool", + "description": "Identify" + }, + { + "type": "00000020-0000-1000-8000-0026BB765291", + "iid": 3, + "perms": ["pr"], + "format": "string", + "value": "Nanoleaf", + "description": "Manufacturer", + "maxLen": 64 + }, + { + "type": "00000021-0000-1000-8000-0026BB765291", + "iid": 4, + "perms": ["pr"], + "format": "string", + "value": "NL55", + "description": "Model", + "maxLen": 64 + }, + { + "type": "00000023-0000-1000-8000-0026BB765291", + "iid": 5, + "perms": ["pr"], + "format": "string", + "value": "Nanoleaf Strip 3B32", + "description": "Name", + "maxLen": 64 + }, + { + "type": "00000030-0000-1000-8000-0026BB765291", + "iid": 6, + "perms": ["pr"], + "format": "string", + "value": "AAAA011111111111", + "description": "Serial Number", + "maxLen": 64 + }, + { + "type": "00000052-0000-1000-8000-0026BB765291", + "iid": 7, + "perms": ["pr"], + "format": "string", + "value": "1.4.40", + "description": "Firmware Revision", + "maxLen": 64 + }, + { + "type": "00000053-0000-1000-8000-0026BB765291", + "iid": 8, + "perms": ["pr"], + "format": "string", + "value": "1.2.4", + "description": "Hardware Revision", + "maxLen": 64 + }, + { + "type": "34AB8811-AC7F-4340-BAC3-FD6A85F9943B", + "iid": 9, + "perms": ["pr", "hd"], + "format": "string", + "value": "5.0;dfeceb3a", + "maxLen": 64 + }, + { + "type": "00000220-0000-1000-8000-0026BB765291", + "iid": 10, + "perms": ["pr", "hd"], + "format": "data", + "value": "cf0c2e5a4476e152" + } + ] + }, + { + "iid": 11, + "type": "00000055-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "0000004C-0000-1000-8000-0026BB765291", + "iid": 34, + "perms": [], + "format": "data", + "description": "Pair Setup" + }, + { + "type": "0000004E-0000-1000-8000-0026BB765291", + "iid": 35, + "perms": [], + "format": "data", + "description": "Pair Verify" + }, + { + "type": "0000004F-0000-1000-8000-0026BB765291", + "iid": 36, + "perms": [], + "format": "uint8", + "description": "Pairing Features" + }, + { + "type": "00000050-0000-1000-8000-0026BB765291", + "iid": 37, + "perms": ["pr", "pw"], + "format": "data", + "value": null, + "description": "Pairing Pairings" + } + ] + }, + { + "iid": 16, + "type": "000000A2-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "000000A5-0000-1000-8000-0026BB765291", + "iid": 17, + "perms": ["pr"], + "format": "data", + "value": "" + }, + { + "type": "00000037-0000-1000-8000-0026BB765291", + "iid": 18, + "perms": ["pr"], + "format": "string", + "value": "2.2.0", + "description": "Version", + "maxLen": 64 + } + ] + }, + { + "iid": 19, + "type": "00000043-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "000000A5-0000-1000-8000-0026BB765291", + "iid": 49, + "perms": ["pr"], + "format": "data", + "value": "" + }, + { + "type": "00000025-0000-1000-8000-0026BB765291", + "iid": 51, + "perms": ["pr", "pw", "ev"], + "format": "bool", + "value": true, + "description": "On" + }, + { + "type": "00000023-0000-1000-8000-0026BB765291", + "iid": 50, + "perms": ["pr"], + "format": "string", + "value": "Nanoleaf Light Strip", + "description": "Name", + "maxLen": 64 + }, + { + "type": "00000008-0000-1000-8000-0026BB765291", + "iid": 52, + "perms": ["pr", "pw", "ev"], + "format": "int", + "value": 100, + "description": "Brightness", + "unit": "percentage", + "minValue": 0, + "maxValue": 100, + "minStep": 1 + }, + { + "type": "000000CE-0000-1000-8000-0026BB765291", + "iid": 55, + "perms": ["pr", "pw", "ev"], + "format": "uint32", + "value": 470, + "description": "Color Temperature", + "minValue": 153, + "maxValue": 470, + "minStep": 1 + }, + { + "type": "00000013-0000-1000-8000-0026BB765291", + "iid": 53, + "perms": ["pr", "pw", "ev"], + "format": "float", + "value": 30.0, + "description": "Hue", + "unit": "arcdegrees", + "minValue": 0.0, + "maxValue": 360.0, + "minStep": 1.0 + }, + { + "type": "0000002F-0000-1000-8000-0026BB765291", + "iid": 54, + "perms": ["pr", "pw", "ev"], + "format": "float", + "value": 89.0, + "description": "Saturation", + "unit": "percentage", + "minValue": 0.0, + "maxValue": 100.0, + "minStep": 1.0 + }, + { + "type": "A28E1902-CFA1-4D37-A10F-0071CEEEEEBD", + "iid": 60, + "perms": ["pr", "pw", "hd"], + "format": "data", + "value": "" + }, + { + "type": "00000143-0000-1000-8000-0026BB765291", + "iid": 56, + "perms": ["pr", "pw"], + "format": "data", + "value": "" + }, + { + "type": "00000144-0000-1000-8000-0026BB765291", + "iid": 57, + "perms": ["pr"], + "format": "data", + "value": "010901013402040100000000000109010137020402000000" + }, + { + "type": "0000024B-0000-1000-8000-0026BB765291", + "iid": 58, + "perms": ["pr", "ev"], + "format": "uint8", + "value": 0, + "minValue": 0, + "maxValue": 2 + } + ] + }, + { + "iid": 31, + "type": "00000701-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "000000A5-0000-1000-8000-0026BB765291", + "iid": 113, + "perms": ["pr"], + "format": "data", + "value": null + }, + { + "type": "00000706-0000-1000-8000-0026BB765291", + "iid": 116, + "perms": ["pr"], + "format": "string", + "value": "", + "maxLen": 64 + }, + { + "type": "00000702-0000-1000-8000-0026BB765291", + "iid": 115, + "perms": ["pr"], + "format": "uint16", + "value": 31, + "description": "Thread Node Capabilities", + "minValue": 0, + "maxValue": 31 + }, + { + "type": "00000703-0000-1000-8000-0026BB765291", + "iid": 117, + "perms": ["pr", "ev"], + "format": "uint16", + "value": 127, + "description": "Thread Status", + "minValue": 0, + "maxValue": 127 + }, + { + "type": "0000022B-0000-1000-8000-0026BB765291", + "iid": 118, + "perms": ["pr"], + "format": "bool", + "value": false + }, + { + "type": "00000704-0000-1000-8000-0026BB765291", + "iid": 119, + "perms": ["pr", "pw"], + "format": "data", + "value": null + } + ] + }, + { + "iid": 38, + "type": "00000239-0000-1000-8000-0026BB765291", + "characteristics": [ + { + "type": "000000A5-0000-1000-8000-0026BB765291", + "iid": 2564, + "perms": ["pr"], + "format": "data", + "value": "" + }, + { + "type": "0000023A-0000-1000-8000-0026BB765291", + "iid": 2561, + "perms": ["pr"], + "format": "uint32", + "value": 0, + "minValue": 0, + "maxValue": 67108863 + }, + { + "type": "0000023C-0000-1000-8000-0026BB765291", + "iid": 2562, + "perms": ["pr"], + "format": "data", + "value": "" + }, + { + "type": "0000024A-0000-1000-8000-0026BB765291", + "iid": 2565, + "perms": ["pr", "ev"], + "format": "uint32", + "value": 1 + } + ] + }, + { + "iid": 43, + "type": "0E9CC677-A71F-8B83-B84D-568278790CB3", + "characteristics": [] + }, + { + "iid": 44, + "type": "6D2AE1C4-9AEA-11EA-BB37-0242AC130002", + "characteristics": [] + } + ] + } +] diff --git a/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py b/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py new file mode 100644 index 00000000000..7e6a9bb672b --- /dev/null +++ b/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py @@ -0,0 +1,55 @@ +"""Make sure that Nanoleaf NL55 works with BLE.""" + +from homeassistant.helpers.entity import EntityCategory + +from tests.components.homekit_controller.common import ( + HUB_TEST_ACCESSORY_ID, + DeviceTestInfo, + EntityTestInfo, + assert_devices_and_entities_created, + setup_accessories_from_file, + setup_test_accessories, +) + +LIGHT_ON = ("lightbulb", "on") + + +async def test_nanoleaf_nl55_setup(hass): + """Test that a Nanoleaf NL55 can be correctly setup in HA.""" + accessories = await setup_accessories_from_file(hass, "nanoleaf_strip_nl55.json") + await setup_test_accessories(hass, accessories) + + await assert_devices_and_entities_created( + hass, + DeviceTestInfo( + unique_id=HUB_TEST_ACCESSORY_ID, + name="Nanoleaf Strip 3B32", + model="NL55", + manufacturer="Nanoleaf", + sw_version="1.4.40", + hw_version="1.2.4", + serial_number="AAAA011111111111", + devices=[], + entities=[ + EntityTestInfo( + entity_id="light.nanoleaf_strip_3b32_nanoleaf_light_strip", + friendly_name="Nanoleaf Strip 3B32 Nanoleaf Light Strip", + unique_id="homekit-AAAA011111111111-19", + supported_features=0, + capabilities={ + "max_mireds": 470, + "min_mireds": 153, + "supported_color_modes": ["color_temp", "hs"], + }, + state="on", + ), + EntityTestInfo( + entity_id="button.nanoleaf_strip_3b32_identify", + friendly_name="Nanoleaf Strip 3B32 Identify", + unique_id="homekit-AAAA011111111111-aid:1-sid:1-cid:2", + entity_category=EntityCategory.DIAGNOSTIC, + state="unknown", + ), + ], + ), + )