Skip to content

Commit

Permalink
Remove deprecated typing and fix thread safety issue
Browse files Browse the repository at this point in the history
  • Loading branch information
niekschoemaker committed Dec 29, 2024
1 parent 70eb6c0 commit 6ffb7a4
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 56 deletions.
6 changes: 3 additions & 3 deletions custom_components/hon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.helpers import config_validation as cv, aiohttp_client
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.core import HomeAssistant
from pyhon import Hon

from .const import DOMAIN, PLATFORMS, MOBILE_ID, CONF_REFRESH_TOKEN
Expand All @@ -27,7 +27,7 @@
)


async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
session = aiohttp_client.async_get_clientsession(hass)
if (config_dir := hass.config.config_dir) is None:
raise ValueError("Missing Config Dir")
Expand Down Expand Up @@ -60,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
return True


async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
refresh_token = hass.data[DOMAIN][entry.unique_id]["hon"].api.auth.refresh_token

hass.config_entries.async_update_entry(
Expand Down
7 changes: 3 additions & 4 deletions custom_components/hon/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType

from .const import DOMAIN
from .entity import HonEntity
Expand Down Expand Up @@ -317,7 +316,7 @@ class HonBinarySensorEntityDescription(BinarySensorEntityDescription):


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
Expand Down Expand Up @@ -346,4 +345,4 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
== self.entity_description.on_value
)
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
8 changes: 4 additions & 4 deletions custom_components/hon/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.core import HomeAssistant
from pyhon.appliance import HonAppliance

from .const import DOMAIN
Expand Down Expand Up @@ -56,7 +56,7 @@


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities: list[HonButtonType] = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
Expand Down Expand Up @@ -88,7 +88,7 @@ def available(self) -> bool:

class HonDeviceInfo(HonEntity, ButtonEntity):
def __init__(
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
) -> None:
super().__init__(hass, entry, device)

Expand All @@ -108,7 +108,7 @@ async def async_press(self) -> None:

class HonDataArchive(HonEntity, ButtonEntity):
def __init__(
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
) -> None:
super().__init__(hass, entry, device)

Expand Down
14 changes: 7 additions & 7 deletions custom_components/hon/climate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
from dataclasses import dataclass
from typing import Any
Expand All @@ -19,9 +20,8 @@
ATTR_TEMPERATURE,
UnitOfTemperature,
)
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand Down Expand Up @@ -104,7 +104,7 @@ class HonClimateEntityDescription(ClimateEntityDescription):


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
entity: HonClimateEntity | HonACClimateEntity
Expand All @@ -130,7 +130,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonACClimateEntityDescription,
Expand Down Expand Up @@ -290,7 +290,7 @@ async def async_set_swing_mode(self, swing_mode: str) -> None:
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()


class HonClimateEntity(HonEntity, ClimateEntity):
Expand All @@ -299,7 +299,7 @@ class HonClimateEntity(HonEntity, ClimateEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonClimateEntityDescription,
Expand Down Expand Up @@ -423,4 +423,4 @@ def _set_temperature_bound(self) -> None:
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
5 changes: 2 additions & 3 deletions custom_components/hon/entity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional, Any

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
)
Expand All @@ -20,7 +19,7 @@ class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: Optional[HonEntityDescription] = None,
Expand Down
9 changes: 4 additions & 5 deletions custom_components/hon/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
FanEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.percentage import (
percentage_to_ranged_value,
ranged_value_to_percentage,
Expand All @@ -36,7 +35,7 @@


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
Expand All @@ -56,7 +55,7 @@ class HonFanEntity(HonEntity, FanEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: FanEntityDescription,
Expand Down Expand Up @@ -125,7 +124,7 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
)
self._attr_percentage = self.percentage
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def available(self) -> bool:
Expand Down
9 changes: 4 additions & 5 deletions custom_components/hon/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
ATTR_BRIGHTNESS,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand Down Expand Up @@ -53,7 +52,7 @@


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
Expand All @@ -73,7 +72,7 @@ class HonLightEntity(HonEntity, LightEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: LightEntityDescription,
Expand Down Expand Up @@ -136,7 +135,7 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_is_on = self.is_on
self._attr_brightness = self.brightness
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def available(self) -> bool:
Expand Down
5 changes: 2 additions & 3 deletions custom_components/hon/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange

Expand All @@ -26,7 +25,7 @@


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
Expand Down
13 changes: 6 additions & 7 deletions custom_components/hon/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTime, UnitOfTemperature
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand Down Expand Up @@ -207,7 +206,7 @@ class HonNumberEntityDescription(NumberEntityDescription):


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
entity: HonNumberEntity | HonConfigNumberEntity
Expand All @@ -230,7 +229,7 @@ class HonNumberEntity(HonEntity, NumberEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonNumberEntityDescription,
Expand Down Expand Up @@ -268,7 +267,7 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_native_step = setting.step
self._attr_native_value = self.native_value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def available(self) -> bool:
Expand All @@ -285,7 +284,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonConfigNumberEntityDescription,
Expand Down Expand Up @@ -324,4 +323,4 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_native_step = setting.step
self._attr_native_value = self.native_value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
9 changes: 4 additions & 5 deletions custom_components/hon/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTemperature, UnitOfTime, REVOLUTIONS_PER_MINUTE
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType

from . import const
from .const import DOMAIN
Expand Down Expand Up @@ -211,7 +210,7 @@ class HonConfigSelectEntityDescription(SelectEntityDescription):


async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
entity: HonSelectEntity | HonConfigSelectEntity
Expand Down Expand Up @@ -271,7 +270,7 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_options = self.options
self._attr_current_option = self.current_option
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def available(self) -> bool:
Expand Down Expand Up @@ -334,4 +333,4 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_options = self.options
self._attr_current_option = self.current_option
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
Loading

0 comments on commit 6ffb7a4

Please sign in to comment.