mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Additional cleanup for Sensibo (#78144)
* Clean sensibo code * Add function to description
This commit is contained in:
parent
7a3ca8278d
commit
167b9cb1a0
@ -4,8 +4,6 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pysensibo.model import SensiboDevice
|
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -77,15 +75,12 @@ class SensiboDeviceButton(SensiboDeviceBaseEntity, ButtonEntity):
|
|||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
"""Press the button."""
|
"""Press the button."""
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=self.entity_description.data_key,
|
key=self.entity_description.data_key,
|
||||||
value=False,
|
value=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_send_api_call(
|
async def async_send_api_call(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api."""
|
"""Make service call to api."""
|
||||||
result = await self._client.async_reset_filter(
|
result = await self._client.async_reset_filter(
|
||||||
self._device_id,
|
self._device_id,
|
||||||
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||||||
from bisect import bisect_left
|
from bisect import bisect_left
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from pysensibo.model import SensiboDevice
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
@ -252,7 +251,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
|
|
||||||
new_temp = _find_valid_target_temp(temperature, self.device_data.temp_list)
|
new_temp = _find_valid_target_temp(temperature, self.device_data.temp_list)
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["targetTemperature"],
|
key=AC_STATE_TO_DATA["targetTemperature"],
|
||||||
value=new_temp,
|
value=new_temp,
|
||||||
name="targetTemperature",
|
name="targetTemperature",
|
||||||
@ -265,7 +263,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
raise HomeAssistantError("Current mode doesn't support setting Fanlevel")
|
raise HomeAssistantError("Current mode doesn't support setting Fanlevel")
|
||||||
|
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["fanLevel"],
|
key=AC_STATE_TO_DATA["fanLevel"],
|
||||||
value=fan_mode,
|
value=fan_mode,
|
||||||
name="fanLevel",
|
name="fanLevel",
|
||||||
@ -276,7 +273,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
if hvac_mode == HVACMode.OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["on"],
|
key=AC_STATE_TO_DATA["on"],
|
||||||
value=False,
|
value=False,
|
||||||
name="on",
|
name="on",
|
||||||
@ -287,7 +283,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
# Turn on if not currently on.
|
# Turn on if not currently on.
|
||||||
if not self.device_data.device_on:
|
if not self.device_data.device_on:
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["on"],
|
key=AC_STATE_TO_DATA["on"],
|
||||||
value=True,
|
value=True,
|
||||||
name="on",
|
name="on",
|
||||||
@ -295,7 +290,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["mode"],
|
key=AC_STATE_TO_DATA["mode"],
|
||||||
value=HA_TO_SENSIBO[hvac_mode],
|
value=HA_TO_SENSIBO[hvac_mode],
|
||||||
name="mode",
|
name="mode",
|
||||||
@ -308,7 +302,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
raise HomeAssistantError("Current mode doesn't support setting Swing")
|
raise HomeAssistantError("Current mode doesn't support setting Swing")
|
||||||
|
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["swing"],
|
key=AC_STATE_TO_DATA["swing"],
|
||||||
value=swing_mode,
|
value=swing_mode,
|
||||||
name="swing",
|
name="swing",
|
||||||
@ -318,7 +311,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn Sensibo unit on."""
|
"""Turn Sensibo unit on."""
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["on"],
|
key=AC_STATE_TO_DATA["on"],
|
||||||
value=True,
|
value=True,
|
||||||
name="on",
|
name="on",
|
||||||
@ -328,7 +320,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn Sensibo unit on."""
|
"""Turn Sensibo unit on."""
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["on"],
|
key=AC_STATE_TO_DATA["on"],
|
||||||
value=False,
|
value=False,
|
||||||
name="on",
|
name="on",
|
||||||
@ -338,7 +329,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
async def async_assume_state(self, state: str) -> None:
|
async def async_assume_state(self, state: str) -> None:
|
||||||
"""Sync state with api."""
|
"""Sync state with api."""
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=AC_STATE_TO_DATA["on"],
|
key=AC_STATE_TO_DATA["on"],
|
||||||
value=state != HVACMode.OFF,
|
value=state != HVACMode.OFF,
|
||||||
name="on",
|
name="on",
|
||||||
@ -353,10 +343,8 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
"acState": {**self.device_data.ac_states, "on": new_state},
|
"acState": {**self.device_data.ac_states, "on": new_state},
|
||||||
}
|
}
|
||||||
await self.api_call_custom_service_timer(
|
await self.api_call_custom_service_timer(
|
||||||
device_data=self.device_data,
|
|
||||||
key="timer_on",
|
key="timer_on",
|
||||||
value=True,
|
value=True,
|
||||||
command="set_timer",
|
|
||||||
data=params,
|
data=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -385,18 +373,15 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
params["primeIntegration"] = outdoor_integration
|
params["primeIntegration"] = outdoor_integration
|
||||||
|
|
||||||
await self.api_call_custom_service_pure_boost(
|
await self.api_call_custom_service_pure_boost(
|
||||||
device_data=self.device_data,
|
|
||||||
key="pure_boost_enabled",
|
key="pure_boost_enabled",
|
||||||
value=True,
|
value=True,
|
||||||
command="set_pure_boost",
|
|
||||||
data=params,
|
data=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_send_api_call(
|
async def async_send_api_call(
|
||||||
self,
|
self,
|
||||||
device_data: SensiboDevice,
|
key: str,
|
||||||
key: Any,
|
|
||||||
value: Any,
|
value: Any,
|
||||||
name: str,
|
name: str,
|
||||||
assumed_state: bool = False,
|
assumed_state: bool = False,
|
||||||
@ -414,10 +399,8 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def api_call_custom_service_timer(
|
async def api_call_custom_service_timer(
|
||||||
self,
|
self,
|
||||||
device_data: SensiboDevice,
|
key: str,
|
||||||
key: Any,
|
|
||||||
value: Any,
|
value: Any,
|
||||||
command: str,
|
|
||||||
data: dict,
|
data: dict,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Make service call to api."""
|
"""Make service call to api."""
|
||||||
@ -428,10 +411,8 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
|
|||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def api_call_custom_service_pure_boost(
|
async def api_call_custom_service_pure_boost(
|
||||||
self,
|
self,
|
||||||
device_data: SensiboDevice,
|
key: str,
|
||||||
key: Any,
|
|
||||||
value: Any,
|
value: Any,
|
||||||
command: str,
|
|
||||||
data: dict,
|
data: dict,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Make service call to api."""
|
"""Make service call to api."""
|
||||||
|
@ -100,14 +100,10 @@ class SensiboNumber(SensiboDeviceBaseEntity, NumberEntity):
|
|||||||
|
|
||||||
async def async_set_native_value(self, value: float) -> None:
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
"""Set value for calibration."""
|
"""Set value for calibration."""
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(key=self.entity_description.key, value=value)
|
||||||
device_data=self.device_data, key=self.entity_description.key, value=value
|
|
||||||
)
|
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_send_api_call(
|
async def async_send_api_call(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api."""
|
"""Make service call to api."""
|
||||||
data = {self.entity_description.remote_key: value}
|
data = {self.entity_description.remote_key: value}
|
||||||
result = await self._client.async_set_calibration(
|
result = await self._client.async_set_calibration(
|
||||||
|
@ -108,15 +108,12 @@ class SensiboSelect(SensiboDeviceBaseEntity, SelectEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
await self.async_send_api_call(
|
await self.async_send_api_call(
|
||||||
device_data=self.device_data,
|
|
||||||
key=self.entity_description.data_key,
|
key=self.entity_description.data_key,
|
||||||
value=option,
|
value=option,
|
||||||
)
|
)
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_send_api_call(
|
async def async_send_api_call(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api."""
|
"""Make service call to api."""
|
||||||
data = {
|
data = {
|
||||||
"name": self.entity_description.key,
|
"name": self.entity_description.key,
|
||||||
|
@ -49,8 +49,8 @@ DEVICE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
|
|||||||
icon="mdi:timer",
|
icon="mdi:timer",
|
||||||
value_fn=lambda data: data.timer_on,
|
value_fn=lambda data: data.timer_on,
|
||||||
extra_fn=lambda data: {"id": data.timer_id, "turn_on": data.timer_state_on},
|
extra_fn=lambda data: {"id": data.timer_id, "turn_on": data.timer_state_on},
|
||||||
command_on="set_timer",
|
command_on="async_turn_on_timer",
|
||||||
command_off="del_timer",
|
command_off="async_turn_off_timer",
|
||||||
data_key="timer_on",
|
data_key="timer_on",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -62,8 +62,8 @@ PURE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
|
|||||||
name="Pure Boost",
|
name="Pure Boost",
|
||||||
value_fn=lambda data: data.pure_boost_enabled,
|
value_fn=lambda data: data.pure_boost_enabled,
|
||||||
extra_fn=None,
|
extra_fn=None,
|
||||||
command_on="set_pure_boost",
|
command_on="async_turn_on_off_pure_boost",
|
||||||
command_off="set_pure_boost",
|
command_off="async_turn_on_off_pure_boost",
|
||||||
data_key="pure_boost_enabled",
|
data_key="pure_boost_enabled",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -113,33 +113,21 @@ class SensiboDeviceSwitch(SensiboDeviceBaseEntity, SwitchEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
if self.entity_description.key == "timer_on_switch":
|
func = getattr(SensiboDeviceSwitch, self.entity_description.command_on)
|
||||||
await self.async_turn_on_timer(
|
await func(
|
||||||
device_data=self.device_data,
|
self,
|
||||||
key=self.entity_description.data_key,
|
key=self.entity_description.data_key,
|
||||||
value=True,
|
value=True,
|
||||||
)
|
)
|
||||||
if self.entity_description.key == "pure_boost_switch":
|
|
||||||
await self.async_turn_on_off_pure_boost(
|
|
||||||
device_data=self.device_data,
|
|
||||||
key=self.entity_description.data_key,
|
|
||||||
value=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
if self.entity_description.key == "timer_on_switch":
|
func = getattr(SensiboDeviceSwitch, self.entity_description.command_off)
|
||||||
await self.async_turn_off_timer(
|
await func(
|
||||||
device_data=self.device_data,
|
self,
|
||||||
key=self.entity_description.data_key,
|
key=self.entity_description.data_key,
|
||||||
value=False,
|
value=True,
|
||||||
)
|
)
|
||||||
if self.entity_description.key == "pure_boost_switch":
|
|
||||||
await self.async_turn_on_off_pure_boost(
|
|
||||||
device_data=self.device_data,
|
|
||||||
key=self.entity_description.data_key,
|
|
||||||
value=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
||||||
@ -149,37 +137,31 @@ class SensiboDeviceSwitch(SensiboDeviceBaseEntity, SwitchEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_turn_on_timer(
|
async def async_turn_on_timer(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api for setting timer."""
|
"""Make service call to api for setting timer."""
|
||||||
result = {}
|
result = {}
|
||||||
new_state = bool(device_data.ac_states["on"] is False)
|
new_state = bool(self.device_data.ac_states["on"] is False)
|
||||||
data = {
|
data = {
|
||||||
"minutesFromNow": 60,
|
"minutesFromNow": 60,
|
||||||
"acState": {**device_data.ac_states, "on": new_state},
|
"acState": {**self.device_data.ac_states, "on": new_state},
|
||||||
}
|
}
|
||||||
result = await self._client.async_set_timer(self._device_id, data)
|
result = await self._client.async_set_timer(self._device_id, data)
|
||||||
return bool(result.get("status") == "success")
|
return bool(result.get("status") == "success")
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_turn_off_timer(
|
async def async_turn_off_timer(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api for deleting timer."""
|
"""Make service call to api for deleting timer."""
|
||||||
result = {}
|
result = {}
|
||||||
result = await self._client.async_del_timer(self._device_id)
|
result = await self._client.async_del_timer(self._device_id)
|
||||||
return bool(result.get("status") == "success")
|
return bool(result.get("status") == "success")
|
||||||
|
|
||||||
@async_handle_api_call
|
@async_handle_api_call
|
||||||
async def async_turn_on_off_pure_boost(
|
async def async_turn_on_off_pure_boost(self, key: str, value: Any) -> bool:
|
||||||
self, device_data: SensiboDevice, key: Any, value: Any
|
|
||||||
) -> bool:
|
|
||||||
"""Make service call to api for setting Pure Boost."""
|
"""Make service call to api for setting Pure Boost."""
|
||||||
result = {}
|
result = {}
|
||||||
new_state = bool(device_data.pure_boost_enabled is False)
|
new_state = bool(self.device_data.pure_boost_enabled is False)
|
||||||
data: dict[str, Any] = {"enabled": new_state}
|
data: dict[str, Any] = {"enabled": new_state}
|
||||||
if device_data.pure_measure_integration is None:
|
if self.device_data.pure_measure_integration is None:
|
||||||
data["sensitivity"] = "N"
|
data["sensitivity"] = "N"
|
||||||
data["measurementsIntegration"] = True
|
data["measurementsIntegration"] = True
|
||||||
data["acIntegration"] = False
|
data["acIntegration"] = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user