mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 21:19:16 +00:00
Remove icloud from mypy ignore list (#75007)
This commit is contained in:
parent
7b5cf63a46
commit
6ac05784a6
@ -1,4 +1,8 @@
|
|||||||
"""The iCloud component."""
|
"""The iCloud component."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -82,7 +86,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
if entry.unique_id is None:
|
if entry.unique_id is None:
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=username)
|
hass.config_entries.async_update_entry(entry, unique_id=username)
|
||||||
|
|
||||||
icloud_dir = Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
icloud_dir = Store[Any](hass, STORAGE_VERSION, STORAGE_KEY)
|
||||||
|
|
||||||
account = IcloudAccount(
|
account = IcloudAccount(
|
||||||
hass,
|
hass,
|
||||||
@ -103,7 +107,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
def play_sound(service: ServiceCall) -> None:
|
def play_sound(service: ServiceCall) -> None:
|
||||||
"""Play sound on the device."""
|
"""Play sound on the device."""
|
||||||
account = service.data[ATTR_ACCOUNT]
|
account = service.data[ATTR_ACCOUNT]
|
||||||
device_name = service.data.get(ATTR_DEVICE_NAME)
|
device_name: str = service.data[ATTR_DEVICE_NAME]
|
||||||
device_name = slugify(device_name.replace(" ", "", 99))
|
device_name = slugify(device_name.replace(" ", "", 99))
|
||||||
|
|
||||||
for device in _get_account(account).get_devices_with_name(device_name):
|
for device in _get_account(account).get_devices_with_name(device_name):
|
||||||
@ -112,7 +116,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
def display_message(service: ServiceCall) -> None:
|
def display_message(service: ServiceCall) -> None:
|
||||||
"""Display a message on the device."""
|
"""Display a message on the device."""
|
||||||
account = service.data[ATTR_ACCOUNT]
|
account = service.data[ATTR_ACCOUNT]
|
||||||
device_name = service.data.get(ATTR_DEVICE_NAME)
|
device_name: str = service.data[ATTR_DEVICE_NAME]
|
||||||
device_name = slugify(device_name.replace(" ", "", 99))
|
device_name = slugify(device_name.replace(" ", "", 99))
|
||||||
message = service.data.get(ATTR_LOST_DEVICE_MESSAGE)
|
message = service.data.get(ATTR_LOST_DEVICE_MESSAGE)
|
||||||
sound = service.data.get(ATTR_LOST_DEVICE_SOUND, False)
|
sound = service.data.get(ATTR_LOST_DEVICE_SOUND, False)
|
||||||
@ -123,7 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
def lost_device(service: ServiceCall) -> None:
|
def lost_device(service: ServiceCall) -> None:
|
||||||
"""Make the device in lost state."""
|
"""Make the device in lost state."""
|
||||||
account = service.data[ATTR_ACCOUNT]
|
account = service.data[ATTR_ACCOUNT]
|
||||||
device_name = service.data.get(ATTR_DEVICE_NAME)
|
device_name: str = service.data[ATTR_DEVICE_NAME]
|
||||||
device_name = slugify(device_name.replace(" ", "", 99))
|
device_name = slugify(device_name.replace(" ", "", 99))
|
||||||
number = service.data.get(ATTR_LOST_DEVICE_NUMBER)
|
number = service.data.get(ATTR_LOST_DEVICE_NUMBER)
|
||||||
message = service.data.get(ATTR_LOST_DEVICE_MESSAGE)
|
message = service.data.get(ATTR_LOST_DEVICE_MESSAGE)
|
||||||
@ -139,11 +143,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
else:
|
else:
|
||||||
_get_account(account).keep_alive()
|
_get_account(account).keep_alive()
|
||||||
|
|
||||||
def _get_account(account_identifier: str) -> any:
|
def _get_account(account_identifier: str) -> IcloudAccount:
|
||||||
if account_identifier is None:
|
if account_identifier is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
icloud_account = hass.data[DOMAIN].get(account_identifier)
|
icloud_account: IcloudAccount | None = hass.data[DOMAIN].get(account_identifier)
|
||||||
if icloud_account is None:
|
if icloud_account is None:
|
||||||
for account in hass.data[DOMAIN].values():
|
for account in hass.data[DOMAIN].values():
|
||||||
if account.username == account_identifier:
|
if account.username == account_identifier:
|
||||||
|
@ -91,21 +91,19 @@ class IcloudAccount:
|
|||||||
self._username = username
|
self._username = username
|
||||||
self._password = password
|
self._password = password
|
||||||
self._with_family = with_family
|
self._with_family = with_family
|
||||||
self._fetch_interval = max_interval
|
self._fetch_interval: float = max_interval
|
||||||
self._max_interval = max_interval
|
self._max_interval = max_interval
|
||||||
self._gps_accuracy_threshold = gps_accuracy_threshold
|
self._gps_accuracy_threshold = gps_accuracy_threshold
|
||||||
|
|
||||||
self._icloud_dir = icloud_dir
|
self._icloud_dir = icloud_dir
|
||||||
|
|
||||||
self.api: PyiCloudService | None = None
|
self.api: PyiCloudService | None = None
|
||||||
self._owner_fullname = None
|
self._owner_fullname: str | None = None
|
||||||
self._family_members_fullname = {}
|
self._family_members_fullname: dict[str, str] = {}
|
||||||
self._devices = {}
|
self._devices: dict[str, IcloudDevice] = {}
|
||||||
self._retried_fetch = False
|
self._retried_fetch = False
|
||||||
self._config_entry = config_entry
|
self._config_entry = config_entry
|
||||||
|
|
||||||
self.listeners = []
|
|
||||||
|
|
||||||
def setup(self) -> None:
|
def setup(self) -> None:
|
||||||
"""Set up an iCloud account."""
|
"""Set up an iCloud account."""
|
||||||
try:
|
try:
|
||||||
@ -271,6 +269,8 @@ class IcloudAccount:
|
|||||||
|
|
||||||
distances = []
|
distances = []
|
||||||
for zone_state in zones:
|
for zone_state in zones:
|
||||||
|
if zone_state is None:
|
||||||
|
continue
|
||||||
zone_state_lat = zone_state.attributes[DEVICE_LOCATION_LATITUDE]
|
zone_state_lat = zone_state.attributes[DEVICE_LOCATION_LATITUDE]
|
||||||
zone_state_long = zone_state.attributes[DEVICE_LOCATION_LONGITUDE]
|
zone_state_long = zone_state.attributes[DEVICE_LOCATION_LONGITUDE]
|
||||||
zone_distance = distance(
|
zone_distance = distance(
|
||||||
@ -279,6 +279,7 @@ class IcloudAccount:
|
|||||||
zone_state_lat,
|
zone_state_lat,
|
||||||
zone_state_long,
|
zone_state_long,
|
||||||
)
|
)
|
||||||
|
if zone_distance is not None:
|
||||||
distances.append(round(zone_distance / 1000, 1))
|
distances.append(round(zone_distance / 1000, 1))
|
||||||
|
|
||||||
# Max interval if no zone
|
# Max interval if no zone
|
||||||
@ -288,7 +289,7 @@ class IcloudAccount:
|
|||||||
|
|
||||||
# Calculate out how long it would take for the device to drive
|
# Calculate out how long it would take for the device to drive
|
||||||
# to the nearest zone at 120 km/h:
|
# to the nearest zone at 120 km/h:
|
||||||
interval = round(mindistance / 2, 0)
|
interval = round(mindistance / 2)
|
||||||
|
|
||||||
# Never poll more than once per minute
|
# Never poll more than once per minute
|
||||||
interval = max(interval, 1)
|
interval = max(interval, 1)
|
||||||
@ -324,7 +325,7 @@ class IcloudAccount:
|
|||||||
self.api.authenticate()
|
self.api.authenticate()
|
||||||
self.update_devices()
|
self.update_devices()
|
||||||
|
|
||||||
def get_devices_with_name(self, name: str) -> [any]:
|
def get_devices_with_name(self, name: str) -> list[Any]:
|
||||||
"""Get devices by name."""
|
"""Get devices by name."""
|
||||||
result = []
|
result = []
|
||||||
name_slug = slugify(name.replace(" ", "", 99))
|
name_slug = slugify(name.replace(" ", "", 99))
|
||||||
@ -341,7 +342,7 @@ class IcloudAccount:
|
|||||||
return self._username
|
return self._username
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def owner_fullname(self) -> str:
|
def owner_fullname(self) -> str | None:
|
||||||
"""Return the account owner fullname."""
|
"""Return the account owner fullname."""
|
||||||
return self._owner_fullname
|
return self._owner_fullname
|
||||||
|
|
||||||
@ -351,7 +352,7 @@ class IcloudAccount:
|
|||||||
return self._family_members_fullname
|
return self._family_members_fullname
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fetch_interval(self) -> int:
|
def fetch_interval(self) -> float:
|
||||||
"""Return the account fetch interval."""
|
"""Return the account fetch interval."""
|
||||||
return self._fetch_interval
|
return self._fetch_interval
|
||||||
|
|
||||||
@ -386,14 +387,7 @@ class IcloudDevice:
|
|||||||
self._device_class = self._status[DEVICE_CLASS]
|
self._device_class = self._status[DEVICE_CLASS]
|
||||||
self._device_model = self._status[DEVICE_DISPLAY_NAME]
|
self._device_model = self._status[DEVICE_DISPLAY_NAME]
|
||||||
|
|
||||||
if self._status[DEVICE_PERSON_ID]:
|
self._battery_level: int | None = None
|
||||||
owner_fullname = account.family_members_fullname[
|
|
||||||
self._status[DEVICE_PERSON_ID]
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
owner_fullname = account.owner_fullname
|
|
||||||
|
|
||||||
self._battery_level = None
|
|
||||||
self._battery_status = None
|
self._battery_status = None
|
||||||
self._location = None
|
self._location = None
|
||||||
|
|
||||||
@ -402,8 +396,13 @@ class IcloudDevice:
|
|||||||
ATTR_ACCOUNT_FETCH_INTERVAL: self._account.fetch_interval,
|
ATTR_ACCOUNT_FETCH_INTERVAL: self._account.fetch_interval,
|
||||||
ATTR_DEVICE_NAME: self._device_model,
|
ATTR_DEVICE_NAME: self._device_model,
|
||||||
ATTR_DEVICE_STATUS: None,
|
ATTR_DEVICE_STATUS: None,
|
||||||
ATTR_OWNER_NAME: owner_fullname,
|
|
||||||
}
|
}
|
||||||
|
if self._status[DEVICE_PERSON_ID]:
|
||||||
|
self._attrs[ATTR_OWNER_NAME] = account.family_members_fullname[
|
||||||
|
self._status[DEVICE_PERSON_ID]
|
||||||
|
]
|
||||||
|
elif account.owner_fullname is not None:
|
||||||
|
self._attrs[ATTR_OWNER_NAME] = account.owner_fullname
|
||||||
|
|
||||||
def update(self, status) -> None:
|
def update(self, status) -> None:
|
||||||
"""Update the iCloud device."""
|
"""Update the iCloud device."""
|
||||||
@ -487,17 +486,17 @@ class IcloudDevice:
|
|||||||
return self._device_model
|
return self._device_model
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self) -> int:
|
def battery_level(self) -> int | None:
|
||||||
"""Return the Apple device battery level."""
|
"""Return the Apple device battery level."""
|
||||||
return self._battery_level
|
return self._battery_level
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_status(self) -> str:
|
def battery_status(self) -> str | None:
|
||||||
"""Return the Apple device battery status."""
|
"""Return the Apple device battery status."""
|
||||||
return self._battery_status
|
return self._battery_status
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location(self) -> dict[str, Any]:
|
def location(self) -> dict[str, Any] | None:
|
||||||
"""Return the Apple device location."""
|
"""Return the Apple device location."""
|
||||||
return self._location
|
return self._location
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up device tracker for iCloud component."""
|
"""Set up device tracker for iCloud component."""
|
||||||
account = hass.data[DOMAIN][entry.unique_id]
|
account = hass.data[DOMAIN][entry.unique_id]
|
||||||
tracked = set()
|
tracked = set[str]()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_account():
|
def update_account():
|
||||||
@ -51,7 +51,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def add_entities(account, async_add_entities, tracked):
|
def add_entities(account: IcloudAccount, async_add_entities, tracked):
|
||||||
"""Add new tracker entities from the account."""
|
"""Add new tracker entities from the account."""
|
||||||
new_tracked = []
|
new_tracked = []
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class IcloudTrackerEntity(TrackerEntity):
|
|||||||
return self._device.location[DEVICE_LOCATION_LONGITUDE]
|
return self._device.location[DEVICE_LOCATION_LONGITUDE]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self) -> int:
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the device."""
|
"""Return the battery level of the device."""
|
||||||
return self._device.battery_level
|
return self._device.battery_level
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up device tracker for iCloud component."""
|
"""Set up device tracker for iCloud component."""
|
||||||
account = hass.data[DOMAIN][entry.unique_id]
|
account = hass.data[DOMAIN][entry.unique_id]
|
||||||
tracked = set()
|
tracked = set[str]()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_account():
|
def update_account():
|
||||||
@ -74,7 +74,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
|
|||||||
return f"{self._device.name} battery state"
|
return f"{self._device.name} battery state"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> int:
|
def native_value(self) -> int | None:
|
||||||
"""Battery state percentage."""
|
"""Battery state percentage."""
|
||||||
return self._device.battery_level
|
return self._device.battery_level
|
||||||
|
|
||||||
|
12
mypy.ini
12
mypy.ini
@ -2672,18 +2672,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.evohome.climate]
|
[mypy-homeassistant.components.evohome.climate]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.icloud]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.icloud.account]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.icloud.device_tracker]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.icloud.sensor]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.lovelace]
|
[mypy-homeassistant.components.lovelace]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -25,10 +25,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.conversation.default_agent",
|
"homeassistant.components.conversation.default_agent",
|
||||||
"homeassistant.components.evohome",
|
"homeassistant.components.evohome",
|
||||||
"homeassistant.components.evohome.climate",
|
"homeassistant.components.evohome.climate",
|
||||||
"homeassistant.components.icloud",
|
|
||||||
"homeassistant.components.icloud.account",
|
|
||||||
"homeassistant.components.icloud.device_tracker",
|
|
||||||
"homeassistant.components.icloud.sensor",
|
|
||||||
"homeassistant.components.lovelace",
|
"homeassistant.components.lovelace",
|
||||||
"homeassistant.components.lovelace.dashboard",
|
"homeassistant.components.lovelace.dashboard",
|
||||||
"homeassistant.components.lovelace.resources",
|
"homeassistant.components.lovelace.resources",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user