Enable mypy checks for homekit_controller (#65358)

pull/65365/head
Jc2k 2022-02-01 11:27:35 +00:00 committed by GitHub
parent ab17f8984b
commit dd5bcafab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 18 deletions

View File

@ -48,8 +48,6 @@ class HomeKitEntity(Entity):
self._features = 0
self.setup()
self._signals = []
super().__init__()
@property
@ -71,7 +69,7 @@ class HomeKitEntity(Entity):
async def async_added_to_hass(self):
"""Entity added to hass."""
self._signals.append(
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
self._accessory.signal_state_updated, self.async_write_ha_state
)
@ -85,10 +83,6 @@ class HomeKitEntity(Entity):
self._accessory.remove_pollable_characteristics(self._aid)
self._accessory.remove_watchable_characteristics(self._aid)
for signal_remove in self._signals:
signal_remove()
self._signals.clear()
async def async_put_characteristics(self, characteristics: dict[str, Any]):
"""
Write characteristics to the device.
@ -145,7 +139,7 @@ class HomeKitEntity(Entity):
return f"homekit-{self._accessory.unique_id}-{self._aid}-{self._iid}"
@property
def name(self) -> str:
def name(self) -> str | None:
"""Return the name of the device if any."""
return self.accessory_info.value(CharacteristicsTypes.NAME)

View File

@ -280,9 +280,13 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if self.controller is None:
await self._async_setup_controller()
# mypy can't see that self._async_setup_controller() always sets self.controller or throws
assert self.controller
pairing = self.controller.load_pairing(
existing.data["AccessoryPairingID"], dict(existing.data)
)
try:
await pairing.list_accessories_and_characteristics()
except AuthenticationError:

View File

@ -76,7 +76,7 @@ class TriggerSource:
async def async_attach_trigger(
self,
config: TRIGGER_SCHEMA,
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE:

View File

@ -44,7 +44,7 @@ async def async_get_device_diagnostics(
def _async_get_diagnostics_for_device(
hass: HomeAssistant, device: DeviceEntry
) -> dict[str, Any]:
data = {}
data: dict[str, Any] = {}
data["name"] = device.name
data["model"] = device.model
@ -60,7 +60,7 @@ def _async_get_diagnostics_for_device(
include_disabled_entities=True,
)
hass_entities.sort(key=lambda entry: entry.original_name)
hass_entities.sort(key=lambda entry: entry.original_name or "")
for entity_entry in hass_entities:
state = hass.states.get(entity_entry.entity_id)
@ -95,7 +95,7 @@ def _async_get_diagnostics(
hkid = entry.data["AccessoryPairingID"]
connection: HKDevice = hass.data[KNOWN_DEVICES][hkid]
data = {
data: dict[str, Any] = {
"config-entry": {
"title": entry.title,
"version": entry.version,
@ -123,6 +123,8 @@ def _async_get_diagnostics(
devices = data["devices"] = []
for device_id in connection.devices.values():
device = device_registry.async_get(device_id)
if not device:
continue
devices.append(_async_get_diagnostics_for_device(hass, device))
return data

View File

@ -122,7 +122,7 @@ class HomeKitNumber(CharacteristicEntity, NumberEntity):
super().__init__(conn, info, char)
@property
def name(self) -> str:
def name(self) -> str | None:
"""Return the name of the device if any."""
if prefix := super().name:
return f"{prefix} {self.entity_description.name}"

View File

@ -143,7 +143,7 @@ class DeclarativeCharacteristicSwitch(CharacteristicEntity, SwitchEntity):
super().__init__(conn, info, char)
@property
def name(self) -> str:
def name(self) -> str | None:
"""Return the name of the device if any."""
if prefix := super().name:
return f"{prefix} {self.entity_description.name}"

View File

@ -2088,9 +2088,6 @@ ignore_errors = true
[mypy-homeassistant.components.homekit.*]
ignore_errors = true
[mypy-homeassistant.components.homekit_controller.*]
ignore_errors = true
[mypy-homeassistant.components.honeywell.*]
ignore_errors = true

View File

@ -35,7 +35,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.here_travel_time.*",
"homeassistant.components.home_plus_control.*",
"homeassistant.components.homekit.*",
"homeassistant.components.homekit_controller.*",
"homeassistant.components.honeywell.*",
"homeassistant.components.icloud.*",
"homeassistant.components.influxdb.*",