Skip to content

Commit

Permalink
chore: typing __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 committed May 28, 2024
1 parent 7363505 commit 71cdf74
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import cast
from typing import Any, cast

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand All @@ -13,6 +13,8 @@
CONF_TOKEN,
CONF_TYPE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import ConfigType
from homeassistant.core import HomeAssistant
from midealocal.devices import device_selector

Expand All @@ -32,7 +34,7 @@
_LOGGER = logging.getLogger(__name__)


async def update_listener(hass, config_entry):
async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
for platform in ALL_PLATFORM:
await hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in ALL_PLATFORM:
Expand All @@ -52,7 +54,7 @@ async def update_listener(hass, config_entry):
dev.set_refresh_interval(refresh_interval)


async def async_setup(hass: HomeAssistant, hass_config: dict):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.data.setdefault(DOMAIN, {})
attributes = []
for device_entities in MIDEA_DEVICES.values():
Expand All @@ -65,15 +67,17 @@ async def async_setup(hass: HomeAssistant, hass_config: dict):
):
attributes.append(attribute_name.value)

def service_set_attribute(service):
device_id = service.data.get("device_id")
attr = service.data.get("attribute")
value = service.data.get("value")
def service_set_attribute(service: Any) -> None:
device_id = service.data["device_id"]
attr = service.data["attribute"]
value = service.data["value"]
dev = hass.data[DOMAIN][DEVICES].get(device_id)
if dev:
if attr == "fan_speed" and value == "auto":
value = 102
item = MIDEA_DEVICES.get(dev.device_type).get("entities").get(attr)
item = None
if _dev := MIDEA_DEVICES.get(dev.device_type):
item = cast(dict, _dev["entities"]).get(attr)
if (
item
and (item.get("type") in EXTRA_SWITCH)
Expand All @@ -89,7 +93,7 @@ def service_set_attribute(service):
f"Appliance [{device_id}] has no attribute {attr} or value is invalid"
)

def service_send_command(service):
def service_send_command(service: Any) -> None:
device_id = service.data.get("device_id")
cmd_type = service.data.get("cmd_type")
cmd_body = service.data.get("cmd_body")
Expand Down Expand Up @@ -132,7 +136,7 @@ def service_send_command(service):
return True


async def async_setup_entry(hass: HomeAssistant, config_entry):
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
device_type = config_entry.data.get(CONF_TYPE)
if device_type == CONF_ACCOUNT:
return True
Expand Down Expand Up @@ -188,7 +192,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):
return False


async def async_unload_entry(hass: HomeAssistant, config_entry):
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
device_type = config_entry.data.get(CONF_TYPE)
if device_type == CONF_ACCOUNT:
return True
Expand Down

0 comments on commit 71cdf74

Please sign in to comment.