From 788134cbc408cec45e1ff2014d112a8cdaf1683c Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 20 Feb 2021 03:50:00 -0500 Subject: [PATCH] Bump zwave-js-server-python to 0.18.0 (#46787) * updates to support changes in zwave-js-server-python * bump lib version * use named arguments for optional args * re-add lost commits --- homeassistant/components/zwave_js/climate.py | 10 +++++- homeassistant/components/zwave_js/entity.py | 21 ++++++----- homeassistant/components/zwave_js/light.py | 36 ++++++++++++++----- .../components/zwave_js/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/zwave_js/test_climate.py | 1 - tests/components/zwave_js/test_light.py | 16 ++++++--- 8 files changed, 63 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index 341b8f99fd6..f864efe91ff 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -125,10 +125,18 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): ) self._setpoint_values: Dict[ThermostatSetpointType, ZwaveValue] = {} for enum in ThermostatSetpointType: + # Some devices don't include a property key so we need to check for value + # ID's, both with and without the property key self._setpoint_values[enum] = self.get_zwave_value( THERMOSTAT_SETPOINT_PROPERTY, command_class=CommandClass.THERMOSTAT_SETPOINT, - value_property_key_name=enum.value, + value_property_key=enum.value.key, + value_property_key_name=enum.value.name, + add_to_watched_value_ids=True, + ) or self.get_zwave_value( + THERMOSTAT_SETPOINT_PROPERTY, + command_class=CommandClass.THERMOSTAT_SETPOINT, + value_property_key_name=enum.value.name, add_to_watched_value_ids=True, ) # Use the first found setpoint value to always determine the temperature unit diff --git a/homeassistant/components/zwave_js/entity.py b/homeassistant/components/zwave_js/entity.py index 911b0b7b2f8..3e81bfaeadf 100644 --- a/homeassistant/components/zwave_js/entity.py +++ b/homeassistant/components/zwave_js/entity.py @@ -134,6 +134,7 @@ class ZWaveBaseEntity(Entity): value_property: Union[str, int], command_class: Optional[int] = None, endpoint: Optional[int] = None, + value_property_key: Optional[int] = None, value_property_key_name: Optional[str] = None, add_to_watched_value_ids: bool = True, check_all_endpoints: bool = False, @@ -146,16 +147,14 @@ class ZWaveBaseEntity(Entity): if endpoint is None: endpoint = self.info.primary_value.endpoint - # Build partial event data dictionary so we can change the endpoint later - partial_evt_data = { - "commandClass": command_class, - "property": value_property, - "propertyKeyName": value_property_key_name, - } - # lookup value by value_id value_id = get_value_id( - self.info.node, {**partial_evt_data, "endpoint": endpoint} + self.info.node, + command_class, + value_property, + endpoint=endpoint, + property_key=value_property_key, + property_key_name=value_property_key_name, ) return_value = self.info.node.values.get(value_id) @@ -166,7 +165,11 @@ class ZWaveBaseEntity(Entity): if endpoint_.index != self.info.primary_value.endpoint: value_id = get_value_id( self.info.node, - {**partial_evt_data, "endpoint": endpoint_.index}, + command_class, + value_property, + endpoint=endpoint_.index, + property_key=value_property_key, + property_key_name=value_property_key_name, ) return_value = self.info.node.values.get(value_id) if return_value: diff --git a/homeassistant/components/zwave_js/light.py b/homeassistant/components/zwave_js/light.py index dd444fdb40d..6ed0286e184 100644 --- a/homeassistant/components/zwave_js/light.py +++ b/homeassistant/components/zwave_js/light.py @@ -3,7 +3,7 @@ import logging from typing import Any, Callable, Optional, Tuple from zwave_js_server.client import Client as ZwaveClient -from zwave_js_server.const import CommandClass +from zwave_js_server.const import ColorComponent, CommandClass from homeassistant.components.light import ( ATTR_BRIGHTNESS, @@ -200,10 +200,18 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity): async def _async_set_color(self, color_name: str, new_value: int) -> None: """Set defined color to given value.""" + try: + property_key = ColorComponent[color_name.upper().replace(" ", "_")].value + except KeyError: + raise ValueError( + "Illegal color name specified, color must be one of " + f"{','.join([color.name for color in ColorComponent])}" + ) from None cur_zwave_value = self.get_zwave_value( "currentColor", CommandClass.SWITCH_COLOR, - value_property_key_name=color_name, + value_property_key=property_key.key, + value_property_key_name=property_key.name, ) # guard for unsupported command if cur_zwave_value is None: @@ -212,7 +220,8 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity): target_zwave_value = self.get_zwave_value( "targetColor", CommandClass.SWITCH_COLOR, - value_property_key_name=color_name, + value_property_key=property_key.key, + value_property_key_name=property_key.name, ) if target_zwave_value is None: return @@ -276,13 +285,22 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity): # RGB support red_val = self.get_zwave_value( - "currentColor", CommandClass.SWITCH_COLOR, value_property_key_name="Red" + "currentColor", + CommandClass.SWITCH_COLOR, + value_property_key=ColorComponent.RED.value.key, + value_property_key_name=ColorComponent.RED.value.name, ) green_val = self.get_zwave_value( - "currentColor", CommandClass.SWITCH_COLOR, value_property_key_name="Green" + "currentColor", + CommandClass.SWITCH_COLOR, + value_property_key=ColorComponent.GREEN.value.key, + value_property_key_name=ColorComponent.GREEN.value.name, ) blue_val = self.get_zwave_value( - "currentColor", CommandClass.SWITCH_COLOR, value_property_key_name="Blue" + "currentColor", + CommandClass.SWITCH_COLOR, + value_property_key=ColorComponent.BLUE.value.key, + value_property_key_name=ColorComponent.BLUE.value.name, ) if red_val and green_val and blue_val: self._supports_color = True @@ -300,12 +318,14 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity): ww_val = self.get_zwave_value( "currentColor", CommandClass.SWITCH_COLOR, - value_property_key_name="Warm White", + value_property_key=ColorComponent.WARM_WHITE.value.key, + value_property_key_name=ColorComponent.WARM_WHITE.value.name, ) cw_val = self.get_zwave_value( "currentColor", CommandClass.SWITCH_COLOR, - value_property_key_name="Cold White", + value_property_key=ColorComponent.COLD_WHITE.value.key, + value_property_key_name=ColorComponent.COLD_WHITE.value.name, ) if ww_val and cw_val: # Color temperature (CW + WW) Support diff --git a/homeassistant/components/zwave_js/manifest.json b/homeassistant/components/zwave_js/manifest.json index 4bd12baa685..56e60fc322c 100644 --- a/homeassistant/components/zwave_js/manifest.json +++ b/homeassistant/components/zwave_js/manifest.json @@ -3,7 +3,7 @@ "name": "Z-Wave JS", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/zwave_js", - "requirements": ["zwave-js-server-python==0.17.2"], + "requirements": ["zwave-js-server-python==0.18.0"], "codeowners": ["@home-assistant/z-wave"], "dependencies": ["http", "websocket_api"] } diff --git a/requirements_all.txt b/requirements_all.txt index 971b8ac9c92..d8d91f2213c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2385,4 +2385,4 @@ zigpy==0.32.0 zm-py==0.5.2 # homeassistant.components.zwave_js -zwave-js-server-python==0.17.2 +zwave-js-server-python==0.18.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c552f8452c0..65c9a788f31 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1222,4 +1222,4 @@ zigpy-znp==0.3.0 zigpy==0.32.0 # homeassistant.components.zwave_js -zwave-js-server-python==0.17.2 +zwave-js-server-python==0.18.0 diff --git a/tests/components/zwave_js/test_climate.py b/tests/components/zwave_js/test_climate.py index 7336acd82eb..17f4dd38144 100644 --- a/tests/components/zwave_js/test_climate.py +++ b/tests/components/zwave_js/test_climate.py @@ -456,7 +456,6 @@ async def test_setpoint_thermostat(hass, client, climate_danfoss_lc_13, integrat "commandClass": 67, "endpoint": 0, "property": "setpoint", - "propertyKey": 1, "propertyKeyName": "Heating", "propertyName": "setpoint", "newValue": 23, diff --git a/tests/components/zwave_js/test_light.py b/tests/components/zwave_js/test_light.py index bcd9a2edd9f..40950362ad7 100644 --- a/tests/components/zwave_js/test_light.py +++ b/tests/components/zwave_js/test_light.py @@ -203,17 +203,21 @@ async def test_light(hass, client, bulb_6_multi_color, integration): "property": "currentColor", "newValue": 255, "prevValue": 0, + "propertyKey": 2, "propertyKeyName": "Red", }, }, ) green_event = deepcopy(red_event) - green_event.data["args"].update({"newValue": 76, "propertyKeyName": "Green"}) + green_event.data["args"].update( + {"newValue": 76, "propertyKey": 3, "propertyKeyName": "Green"} + ) blue_event = deepcopy(red_event) + blue_event.data["args"]["propertyKey"] = 4 blue_event.data["args"]["propertyKeyName"] = "Blue" warm_white_event = deepcopy(red_event) warm_white_event.data["args"].update( - {"newValue": 0, "propertyKeyName": "Warm White"} + {"newValue": 0, "propertyKey": 0, "propertyKeyName": "Warm White"} ) node.receive_event(warm_white_event) node.receive_event(red_event) @@ -316,23 +320,25 @@ async def test_light(hass, client, bulb_6_multi_color, integration): "property": "currentColor", "newValue": 0, "prevValue": 255, + "propertyKey": 2, "propertyKeyName": "Red", }, }, ) green_event = deepcopy(red_event) green_event.data["args"].update( - {"newValue": 0, "prevValue": 76, "propertyKeyName": "Green"} + {"newValue": 0, "prevValue": 76, "propertyKey": 3, "propertyKeyName": "Green"} ) blue_event = deepcopy(red_event) + blue_event.data["args"]["propertyKey"] = 4 blue_event.data["args"]["propertyKeyName"] = "Blue" warm_white_event = deepcopy(red_event) warm_white_event.data["args"].update( - {"newValue": 20, "propertyKeyName": "Warm White"} + {"newValue": 20, "propertyKey": 0, "propertyKeyName": "Warm White"} ) cold_white_event = deepcopy(red_event) cold_white_event.data["args"].update( - {"newValue": 235, "propertyKeyName": "Cold White"} + {"newValue": 235, "propertyKey": 1, "propertyKeyName": "Cold White"} ) node.receive_event(red_event) node.receive_event(green_event)