Sensibo select platform translations (#82743)

This commit is contained in:
G Johansson 2023-01-04 18:17:57 +01:00 committed by GitHub
parent ee21bc5d7f
commit a5225a3606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 16 deletions

View file

@ -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,

View file

@ -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",

View file

@ -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"],
)

View file

@ -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"
}
}
}
}
}

View file

@ -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": {

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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"