Skip to content

Commit

Permalink
fix(core): bump to plugp100 5.1.1 to fix klap retry
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea committed Apr 8, 2024
1 parent cb49f88 commit 80bd250
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 164 deletions.
1 change: 1 addition & 0 deletions custom_components/tapo/hub/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
BatteryComponent: 'LowBatterySensor'
}


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
):
Expand Down
5 changes: 3 additions & 2 deletions custom_components/tapo/hub/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ async def async_setup_entry(
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
for child_coordinator in data.child_coordinators:
if isinstance(child_coordinator.device, KE100Device):
async_add_entities([TRVClimate(child_coordinator, child_coordinator.device)], True)
device = child_coordinator.device
if isinstance(device, KE100Device):
async_add_entities([TRVClimate(child_coordinator, device)], True)


class TRVClimate(CoordinatedTapoEntity, ClimateEntity):
Expand Down
20 changes: 0 additions & 20 deletions custom_components/tapo/hub/hass_tapo_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,6 @@ async def setup_children(

return coordinators


#
# def _create_child_device(child_state: HubChildBaseInfo, hub: HubDevice):
# model = child_state.model.lower()
# device_id = child_state.device_id
# if "t31" in model:
# return T31Device(hub, device_id)
# elif "t110" in model:
# return T110SmartDoor(hub, device_id)
# elif "s200" in model:
# return S200ButtonDevice(hub, device_id)
# elif "t100" in model:
# return T100MotionSensor(hub, device_id)
# elif "ke100" in model:
# return KE100Device(hub, device_id)
# elif any(supported in model for supported in ["s220", "s210"]):
# return SwitchChildDevice(hub, device_id)
# return None


async def _on_options_update_listener(hass: HomeAssistant, config_entry: ConfigEntry):
"""Handle options update."""
await hass.config_entries.async_reload(config_entry.entry_id)
5 changes: 3 additions & 2 deletions custom_components/tapo/hub/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ async def async_setup_entry(
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
for child_coordinator in data.child_coordinators:
if isinstance(child_coordinator.device, KE100Device):
device = child_coordinator.device
if isinstance(device, KE100Device):
async_add_entities(
[TRVTemperatureOffset(child_coordinator, child_coordinator.device)],
[TRVTemperatureOffset(child_coordinator, device)],
True
)

Expand Down
29 changes: 14 additions & 15 deletions custom_components/tapo/hub/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
BatteryComponent: 'BatteryLevelSensor'
}


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
for child_coordinator in data.child_coordinators:
Expand All @@ -56,9 +57,9 @@ class HumiditySensor(CoordinatedTapoEntity, SensorEntity):
_attr_has_entity_name = True

def __init__(
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
):
super().__init__(coordinator, device)
self._attr_name = "Humidity"
Expand Down Expand Up @@ -92,9 +93,9 @@ class TemperatureSensor(CoordinatedTapoEntity, SensorEntity):
_temperature_component: TemperatureComponent

def __init__(
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
):
super().__init__(coordinator, device)
self._attr_name = "Temperature"
Expand Down Expand Up @@ -130,9 +131,9 @@ class BatteryLevelSensor(CoordinatedTapoEntity, SensorEntity):
_attr_has_entity_name = True

def __init__(
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
):
super().__init__(coordinator, device)
self._attr_name = "Battery Percentage"
Expand Down Expand Up @@ -161,9 +162,9 @@ def native_value(self) -> Union[StateType, date, datetime]:
class ReportIntervalDiagnostic(CoordinatedTapoEntity, SensorEntity):

def __init__(
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
self,
coordinator: TapoDataCoordinator,
device: TapoDevice
):
super().__init__(coordinator, device)
self._attr_name = "Report Interval"
Expand All @@ -188,5 +189,3 @@ def native_unit_of_measurement(self) -> Optional[str]:
@property
def native_value(self) -> Union[StateType, date, datetime]:
return self.device.get_component(ReportModeComponent).report_interval_seconds


2 changes: 1 addition & 1 deletion custom_components/tapo/hub/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def async_setup_entry(
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
if isinstance(data.device, TapoHub):
if data.coordinator.device.has_alarm:
if data.device.has_alarm:
available_tones = (
(await data.device.get_supported_alarm_tones())
.get_or_raise()
Expand Down
11 changes: 6 additions & 5 deletions custom_components/tapo/hub/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ async def async_setup_entry(
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
for child_coordinator in data.child_coordinators:
if isinstance(child_coordinator.device, SwitchChildDevice):
device = child_coordinator.device
if isinstance(device, SwitchChildDevice):
async_add_entities([
SwitchTapoChild(child_coordinator, child_coordinator.device)
SwitchTapoChild(child_coordinator, device)
], True)
elif isinstance(child_coordinator.device, KE100Device):
elif isinstance(device, KE100Device):
async_add_entities([
TRVFrostProtection(child_coordinator, child_coordinator.device),
TRVChildLock(child_coordinator, child_coordinator.device)
TRVFrostProtection(child_coordinator, device),
TRVChildLock(child_coordinator, device)
], True)


Expand Down
81 changes: 0 additions & 81 deletions custom_components/tapo/hub/tapo_hub_child_coordinator.py

This file was deleted.

30 changes: 13 additions & 17 deletions custom_components/tapo/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
):
data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id])
if isinstance(data.device, TapoBulb):
Expand Down Expand Up @@ -78,19 +78,13 @@ def is_on(self):
@property
def brightness(self):
return tapo_to_hass_brightness(self.device.brightness)
# current_brightness = (
# self._light_state.lighting_effect.brightness
# if self._has_light_effect_enabled()
# else self._light_state.brightness
# )
# return tapo_to_hass_brightness(current_brightness)

@property
def hs_color(self):
(hue, saturation) = (self.device.hs.hue, self.device.hs.saturation)
color_temp = self.device.color_temp
if (
color_temp is None or color_temp <= 0
color_temp is None or color_temp <= 0
): # returns None if color_temp is not set
if hue is not None and saturation is not None:
return hue, saturation
Expand All @@ -108,6 +102,7 @@ def effect(self) -> Optional[str]:
return effect.name.lower()
else:
return None

async def async_turn_on(self, **kwargs):
brightness = kwargs.get(ATTR_BRIGHTNESS)
color = kwargs.get(ATTR_HS_COLOR)
Expand Down Expand Up @@ -145,13 +140,13 @@ async def async_turn_off(self, **kwargs):
await self.coordinator.async_request_refresh()

async def _set_state(
self,
on: bool,
color_temp=None,
hue_saturation=None,
brightness=None,
effect: str = None,
current_effect: str = None,
self,
on: bool,
color_temp=None,
hue_saturation=None,
brightness=None,
effect: str = None,
current_effect: str = None,
):
if not on:
return (await self.device.turn_off()).get_or_raise()
Expand All @@ -170,8 +165,8 @@ async def _set_state(
await self.device.set_hue_saturation(hue, saturation)
).get_or_raise()
elif (
color_temp is not None
and ColorMode.COLOR_TEMP in self.supported_color_modes
color_temp is not None
and ColorMode.COLOR_TEMP in self.supported_color_modes
):
color_temp = int(color_temp)
(
Expand Down Expand Up @@ -204,6 +199,7 @@ async def _change_brightness(self, new_brightness, apply_to_effect: str = None):
await self.device.set_brightness(new_brightness)
).get_or_raise()


# follows https://developers.home-assistant.io/docs/core/entity/light/#color-modes
def _components_to_color_modes(device: TapoBulb) -> set[ColorMode]:
color_modes = []
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tapo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"iot_class": "local_polling",
"documentation": "https://github.com/petretiandrea/home-assistant-tapo-p100",
"issue_tracker": "https://github.com/petretiandrea/home-assistant-tapo-p100/issues",
"requirements": ["plugp100==5.0.0"],
"requirements": ["plugp100==5.1.1"],
"dependencies": ["network"],
"dhcp": [
{
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tapo/sensors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ def get_config(self) -> SensorConfig:
def get_value(self, coordinator: TapoDataCoordinator) -> StateType:
if energy := coordinator.device.get_component(EnergyComponent):
return energy.energy_info.month_runtime if energy.energy_info else None
return None
return None
19 changes: 2 additions & 17 deletions custom_components/tapo/setup_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,20 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from plugp100.common.credentials import AuthCredential
from plugp100.discovery import DiscoveredDevice
from plugp100.new.device_factory import DeviceConnectConfiguration

from custom_components.tapo.const import CONF_HOST, CONF_DISCOVERED_DEVICE_INFO
from custom_components.tapo.const import CONF_HOST
from custom_components.tapo.const import CONF_PASSWORD
from custom_components.tapo.const import CONF_USERNAME

_LOGGGER = logging.getLogger(__name__)


# async def create_api_from_config(
# hass: HomeAssistant, config: ConfigEntry
# ) -> TapoClient:
# credential = AuthCredential(
# config.data.get(CONF_USERNAME), config.data.get(CONF_PASSWORD)
# )
# _LOGGGER.debug(
# "Creating new API to create a coordinator for %s to address %s",
# config.unique_id,
# config.data.get(CONF_HOST),
# )
# session = async_create_clientsession(hass)
# host, port = get_host_port(config.data.get(CONF_HOST))
# return TapoClient.create(credential, address=host, port=port, http_session=session)

def create_aiohttp_session(hass: HomeAssistant) -> ClientSession:
session = async_create_clientsession(hass, cookie_jar=aiohttp.CookieJar(unsafe=True, quote_cookie=False))
return session


def create_device_config(config: ConfigEntry) -> DeviceConnectConfiguration:
credential = AuthCredential(
config.data.get(CONF_USERNAME), config.data.get(CONF_PASSWORD)
Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
homeassistant==2024.2.0
plugp100==5.0.0
homeassistant==2024.3.3
plugp100==5.1.1
pre-commit==3.3.3
reorder-python-imports==3.10.0
flake8==6.1.0
Expand Down

0 comments on commit 80bd250

Please sign in to comment.