diff --git a/homeassistant/components/homekit_controller/__init__.py b/homeassistant/components/homekit_controller/__init__.py index 0f231fa9303..ed65a83a1e7 100644 --- a/homeassistant/components/homekit_controller/__init__.py +++ b/homeassistant/components/homekit_controller/__init__.py @@ -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) diff --git a/homeassistant/components/homekit_controller/config_flow.py b/homeassistant/components/homekit_controller/config_flow.py index 18f19265f59..6a2200b69eb 100644 --- a/homeassistant/components/homekit_controller/config_flow.py +++ b/homeassistant/components/homekit_controller/config_flow.py @@ -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: diff --git a/homeassistant/components/homekit_controller/device_trigger.py b/homeassistant/components/homekit_controller/device_trigger.py index 0ad64723478..a69d189ebd5 100644 --- a/homeassistant/components/homekit_controller/device_trigger.py +++ b/homeassistant/components/homekit_controller/device_trigger.py @@ -76,7 +76,7 @@ class TriggerSource: async def async_attach_trigger( self, - config: TRIGGER_SCHEMA, + config: ConfigType, action: AutomationActionType, automation_info: AutomationTriggerInfo, ) -> CALLBACK_TYPE: diff --git a/homeassistant/components/homekit_controller/diagnostics.py b/homeassistant/components/homekit_controller/diagnostics.py index e5183b7be31..fd404636a22 100644 --- a/homeassistant/components/homekit_controller/diagnostics.py +++ b/homeassistant/components/homekit_controller/diagnostics.py @@ -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 diff --git a/homeassistant/components/homekit_controller/number.py b/homeassistant/components/homekit_controller/number.py index 3cfe842e856..9c28bc8ebdd 100644 --- a/homeassistant/components/homekit_controller/number.py +++ b/homeassistant/components/homekit_controller/number.py @@ -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}" diff --git a/homeassistant/components/homekit_controller/switch.py b/homeassistant/components/homekit_controller/switch.py index 2645907a962..c681ca4d288 100644 --- a/homeassistant/components/homekit_controller/switch.py +++ b/homeassistant/components/homekit_controller/switch.py @@ -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}" diff --git a/mypy.ini b/mypy.ini index f41ebd8b1ce..7e35a4929f8 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 06c1353ce73..bb1cc2a6679 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -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.*",