Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated typing and fix thread safety issue #275

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 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 All @@ -48,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
coordinator: DataUpdateCoordinator[dict[str, Any]] = DataUpdateCoordinator(
hass, _LOGGER, name=DOMAIN
)
hon.subscribe_updates(coordinator.async_set_updated_data)
hon.subscribe_updates(lambda data: hass.add_job(coordinator.async_set_updated_data, data))

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator}
Expand All @@ -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()
7 changes: 3 additions & 4 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 Expand Up @@ -53,4 +52,4 @@ def device_info(self) -> DeviceInfo:
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
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