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

Update some deprecated code #360

Open
wants to merge 4 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
4 changes: 2 additions & 2 deletions custom_components/miwifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import cached_property
from typing import Any, Final

from homeassistant.components.device_tracker import ENTITY_ID_FORMAT, SOURCE_TYPE_ROUTER
from homeassistant.components.device_tracker import ENTITY_ID_FORMAT, SourceType
from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -351,7 +351,7 @@ def source_type(self) -> str:
:return str: Source type router
"""

return SOURCE_TYPE_ROUTER
return SourceType.ROUTER

@cached_property
def entity_registry_enabled_default(self) -> bool:
Expand Down
4 changes: 1 addition & 3 deletions custom_components/miwifi/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from __future__ import annotations

from enum import Enum, IntEnum # type: ignore

from homeassistant.backports.enum import StrEnum
from enum import Enum, IntEnum, StrEnum # type: ignore

from .const import (
ATTR_SWITCH_WIFI_2_4,
Expand Down
3 changes: 3 additions & 0 deletions custom_components/miwifi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from homeassistant.components.light import (
ENTITY_ID_FORMAT,
ColorMode,
LightEntity,
LightEntityDescription,
)
Expand Down Expand Up @@ -88,6 +89,8 @@ def __init__(
MiWifiEntity.__init__(self, unique_id, description, updater, ENTITY_ID_FORMAT)

self._attr_is_on = updater.data.get(description.key, False)
self._attr_color_mode = ColorMode.ONOFF
self._attr_supported_color_modes = {ColorMode.ONOFF}
self._change_icon(self._attr_is_on)

def _handle_coordinator_update(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/miwifi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_MEGABYTES, PERCENTAGE, TEMP_CELSIUS
from homeassistant.const import UnitOfInformation, UnitOfTemperature, PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -99,7 +99,7 @@
key=ATTR_SENSOR_MEMORY_TOTAL,
name=ATTR_SENSOR_MEMORY_TOTAL_NAME,
icon="mdi:memory",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
state_class=SensorStateClass.TOTAL,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
Expand All @@ -108,7 +108,7 @@
key=ATTR_SENSOR_TEMPERATURE,
name=ATTR_SENSOR_TEMPERATURE_NAME,
icon="mdi:temperature-celsius",
native_unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
Expand Down
19 changes: 9 additions & 10 deletions custom_components/miwifi/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import homeassistant.components.persistent_notification as pn
import voluptuous as vol
from homeassistant.const import CONF_DEVICE_ID, CONF_IP_ADDRESS, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.typing import ServiceCallType

from .const import (
ATTR_DEVICE_HW_VERSION,
Expand Down Expand Up @@ -54,10 +53,10 @@ def __init__(self, hass: HomeAssistant) -> None:

self.hass = hass

def get_updater(self, service: ServiceCallType) -> LuciUpdater:
def get_updater(self, service: ServiceCall) -> LuciUpdater:
"""Get updater.

:param service: ServiceCallType
:param service: ServiceCall
:return LuciUpdater
"""

Expand All @@ -76,10 +75,10 @@ def get_updater(self, service: ServiceCallType) -> LuciUpdater:
f"Device {device_id} does not support the called service. Choose a router with MiWifi support." # pylint: disable=line-too-long
)

async def async_call_service(self, service: ServiceCallType) -> None:
async def async_call_service(self, service: ServiceCall) -> None:
"""Execute service call.

:param service: ServiceCallType
:param service: ServiceCall
"""

raise NotImplementedError # pragma: no cover
Expand All @@ -91,10 +90,10 @@ class MiWifiCalcPasswdServiceCall(MiWifiServiceCall):
salt_old: str = "A2E371B0-B34B-48A5-8C40-A7133F3B5D88"
salt_new: str = "6d2df50a-250f-4a30-a5e6-d44fb0960aa0"

async def async_call_service(self, service: ServiceCallType) -> None:
async def async_call_service(self, service: ServiceCall) -> None:
"""Execute service call.

:param service: ServiceCallType
:param service: ServiceCall
"""

_updater: LuciUpdater = self.get_updater(service)
Expand Down Expand Up @@ -122,10 +121,10 @@ class MiWifiRequestServiceCall(MiWifiServiceCall):
{vol.Required(CONF_URI): str, vol.Optional(CONF_BODY): dict}
)

async def async_call_service(self, service: ServiceCallType) -> None:
async def async_call_service(self, service: ServiceCall) -> None:
"""Execute service call.

:param service: ServiceCallType
:param service: ServiceCall
"""

updater: LuciUpdater = self.get_updater(service)
Expand Down