From a5225a360662ed2465d04835281d3d2e2dca2604 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 4 Jan 2023 18:17:57 +0100 Subject: [PATCH] Sensibo select platform translations (#82743) --- homeassistant/components/sensibo/climate.py | 7 ++++++ .../components/sensibo/manifest.json | 2 +- homeassistant/components/sensibo/select.py | 11 +++++++++- homeassistant/components/sensibo/strings.json | 22 +++++++++++++++++++ .../components/sensibo/translations/en.json | 22 +++++++++++++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/sensibo/test_climate.py | 12 +++++----- tests/components/sensibo/test_select.py | 12 +++++----- 9 files changed, 76 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/sensibo/climate.py b/homeassistant/components/sensibo/climate.py index 583d25112b4..9afdff43ef0 100644 --- a/homeassistant/components/sensibo/climate.py +++ b/homeassistant/components/sensibo/climate.py @@ -308,11 +308,13 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): if "fanLevel" not in self.device_data.active_features: raise HomeAssistantError("Current mode doesn't support setting Fanlevel") + transformation = self.device_data.fan_modes_translated await self.async_send_api_call( key=AC_STATE_TO_DATA["fanLevel"], value=fan_mode, name="fanLevel", assumed_state=False, + transformation=transformation, ) async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: @@ -347,11 +349,13 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): if "swing" not in self.device_data.active_features: raise HomeAssistantError("Current mode doesn't support setting Swing") + transformation = self.device_data.swing_modes_translated await self.async_send_api_call( key=AC_STATE_TO_DATA["swing"], value=swing_mode, name="swing", assumed_state=False, + transformation=transformation, ) async def async_turn_on(self) -> None: @@ -502,8 +506,11 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): value: Any, name: str, assumed_state: bool = False, + transformation: dict | None = None, ) -> bool: """Make service call to api.""" + if transformation: + value = transformation[value] result = await self._client.async_set_ac_state_property( self._device_id, name, diff --git a/homeassistant/components/sensibo/manifest.json b/homeassistant/components/sensibo/manifest.json index e685e80718f..40e53dd8c79 100644 --- a/homeassistant/components/sensibo/manifest.json +++ b/homeassistant/components/sensibo/manifest.json @@ -2,7 +2,7 @@ "domain": "sensibo", "name": "Sensibo", "documentation": "https://www.home-assistant.io/integrations/sensibo", - "requirements": ["pysensibo==1.0.22"], + "requirements": ["pysensibo==1.0.25"], "config_flow": true, "codeowners": ["@andrey-git", "@gjohansson-ST"], "iot_class": "cloud_polling", diff --git a/homeassistant/components/sensibo/select.py b/homeassistant/components/sensibo/select.py index b69de8d0763..29ebdc89261 100644 --- a/homeassistant/components/sensibo/select.py +++ b/homeassistant/components/sensibo/select.py @@ -27,6 +27,7 @@ class SensiboSelectDescriptionMixin: data_key: str value_fn: Callable[[SensiboDevice], str | None] options_fn: Callable[[SensiboDevice], list[str] | None] + transformation: Callable[[SensiboDevice], dict | None] @dataclass @@ -44,6 +45,8 @@ DEVICE_SELECT_TYPES = ( icon="mdi:air-conditioner", value_fn=lambda data: data.horizontal_swing_mode, options_fn=lambda data: data.horizontal_swing_modes, + translation_key="horizontalswing", + transformation=lambda data: data.horizontal_swing_modes_translated, ), SensiboSelectEntityDescription( key="light", @@ -52,6 +55,8 @@ DEVICE_SELECT_TYPES = ( icon="mdi:flashlight", value_fn=lambda data: data.light_mode, options_fn=lambda data: data.light_modes, + translation_key="light", + transformation=lambda data: data.light_modes_translated, ), ) @@ -116,6 +121,10 @@ class SensiboSelect(SensiboDeviceBaseEntity, SelectEntity): @async_handle_api_call async def async_send_api_call(self, key: str, value: Any) -> bool: """Make service call to api.""" + transformation = self.entity_description.transformation(self.device_data) + if TYPE_CHECKING: + assert transformation is not None + data = { "name": self.entity_description.key, "value": value, @@ -125,7 +134,7 @@ class SensiboSelect(SensiboDeviceBaseEntity, SelectEntity): result = await self._client.async_set_ac_state_property( self._device_id, data["name"], - data["value"], + transformation[data["value"]], data["ac_states"], data["assumed_state"], ) diff --git a/homeassistant/components/sensibo/strings.json b/homeassistant/components/sensibo/strings.json index 21830ff913c..fb3559de91a 100644 --- a/homeassistant/components/sensibo/strings.json +++ b/homeassistant/components/sensibo/strings.json @@ -45,6 +45,28 @@ "humidity": "Humidity" } } + }, + "select": { + "horizontalswing": { + "state": { + "stopped": "Stopped", + "fixedleft": "Fixed left", + "fixedcenterleft": "Fixed center left", + "fixedcenter": "Fixed center", + "fixedcenterright": "Fixed center right", + "fixedright": "Fixed right", + "fixedleftright": "Fixed left right", + "rangecenter": "Range center", + "rangefull": "Range full" + } + }, + "light": { + "state": { + "on": "On", + "dim": "Dim", + "off": "Off" + } + } } } } diff --git a/homeassistant/components/sensibo/translations/en.json b/homeassistant/components/sensibo/translations/en.json index 14a399f63a5..323a186f86b 100644 --- a/homeassistant/components/sensibo/translations/en.json +++ b/homeassistant/components/sensibo/translations/en.json @@ -31,6 +31,28 @@ } }, "entity": { + "select": { + "horizontalswing": { + "state": { + "fixedcenter": "Fixed center", + "fixedcenterleft": "Fixed center left", + "fixedcenterright": "Fixed center right", + "fixedleft": "Fixed left", + "fixedleftright": "Fixed left right", + "fixedright": "Fixed right", + "rangecenter": "Range center", + "rangefull": "Range full", + "stopped": "Stopped" + } + }, + "light": { + "state": { + "dim": "Dim", + "off": "Off", + "on": "On" + } + } + }, "sensor": { "sensitivity": { "state": { diff --git a/requirements_all.txt b/requirements_all.txt index 79ff2acd8ae..d67da01bdbb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1898,7 +1898,7 @@ pysaj==0.0.16 pysdcp==1 # homeassistant.components.sensibo -pysensibo==1.0.22 +pysensibo==1.0.25 # homeassistant.components.serial # homeassistant.components.zha diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 12c2dd5ae40..bb7ac31b497 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1351,7 +1351,7 @@ pyruckus==0.16 pysabnzbd==1.1.1 # homeassistant.components.sensibo -pysensibo==1.0.22 +pysensibo==1.0.25 # homeassistant.components.serial # homeassistant.components.zha diff --git a/tests/components/sensibo/test_climate.py b/tests/components/sensibo/test_climate.py index 224248c2d16..e75e4844c53 100644 --- a/tests/components/sensibo/test_climate.py +++ b/tests/components/sensibo/test_climate.py @@ -99,8 +99,8 @@ async def test_climate( "fan_modes": ["quiet", "low", "medium"], "swing_modes": [ "stopped", - "fixedTop", - "fixedMiddleTop", + "fixedtop", + "fixedmiddletop", ], "current_temperature": 21.2, "temperature": 25, @@ -203,13 +203,13 @@ async def test_climate_swing( await hass.services.async_call( CLIMATE_DOMAIN, SERVICE_SET_SWING_MODE, - {ATTR_ENTITY_ID: state1.entity_id, ATTR_SWING_MODE: "fixedTop"}, + {ATTR_ENTITY_ID: state1.entity_id, ATTR_SWING_MODE: "fixedtop"}, blocking=True, ) await hass.async_block_till_done() state2 = hass.states.get("climate.hallway") - assert state2.attributes["swing_mode"] == "fixedTop" + assert state2.attributes["swing_mode"] == "fixedtop" monkeypatch.setattr( get_data.parsed["ABC999111"], @@ -240,13 +240,13 @@ async def test_climate_swing( await hass.services.async_call( CLIMATE_DOMAIN, SERVICE_SET_SWING_MODE, - {ATTR_ENTITY_ID: state1.entity_id, ATTR_SWING_MODE: "fixedTop"}, + {ATTR_ENTITY_ID: state1.entity_id, ATTR_SWING_MODE: "fixedtop"}, blocking=True, ) await hass.async_block_till_done() state3 = hass.states.get("climate.hallway") - assert state3.attributes["swing_mode"] == "fixedTop" + assert state3.attributes["swing_mode"] == "fixedtop" async def test_climate_temperatures( diff --git a/tests/components/sensibo/test_select.py b/tests/components/sensibo/test_select.py index 0fdf67fd5c2..acde7be41ef 100644 --- a/tests/components/sensibo/test_select.py +++ b/tests/components/sensibo/test_select.py @@ -34,7 +34,7 @@ async def test_select( assert state1.state == "stopped" monkeypatch.setattr( - get_data.parsed["ABC999111"], "horizontal_swing_mode", "fixedLeft" + get_data.parsed["ABC999111"], "horizontal_swing_mode", "fixedleft" ) with patch( @@ -48,7 +48,7 @@ async def test_select( await hass.async_block_till_done() state1 = hass.states.get("select.hallway_horizontal_swing") - assert state1.state == "fixedLeft" + assert state1.state == "fixedleft" async def test_select_set_option( @@ -95,7 +95,7 @@ async def test_select_set_option( await hass.services.async_call( SELECT_DOMAIN, SERVICE_SELECT_OPTION, - {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedLeft"}, + {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedleft"}, blocking=True, ) await hass.async_block_till_done() @@ -136,7 +136,7 @@ async def test_select_set_option( await hass.services.async_call( SELECT_DOMAIN, SERVICE_SELECT_OPTION, - {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedLeft"}, + {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedleft"}, blocking=True, ) await hass.async_block_till_done() @@ -154,10 +154,10 @@ async def test_select_set_option( await hass.services.async_call( SELECT_DOMAIN, SERVICE_SELECT_OPTION, - {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedLeft"}, + {ATTR_ENTITY_ID: state1.entity_id, ATTR_OPTION: "fixedleft"}, blocking=True, ) await hass.async_block_till_done() state2 = hass.states.get("select.hallway_horizontal_swing") - assert state2.state == "fixedLeft" + assert state2.state == "fixedleft"