From e41bc1a0daea84a5ed6744db861d205dd8faabcd Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sat, 31 Jul 2021 23:18:37 +0200 Subject: [PATCH] Activate mypy for hdmi_cec (#53763) * Please mypy. * Remove CEC_DEVICES. --- homeassistant/components/hdmi_cec/__init__.py | 9 ++++----- homeassistant/components/hdmi_cec/media_player.py | 4 +++- homeassistant/components/hdmi_cec/switch.py | 6 ++++-- mypy.ini | 3 --- script/hassfest/mypy_config.py | 1 - 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/hdmi_cec/__init__.py b/homeassistant/components/hdmi_cec/__init__.py index 71826429040..471542824de 100644 --- a/homeassistant/components/hdmi_cec/__init__.py +++ b/homeassistant/components/hdmi_cec/__init__.py @@ -1,5 +1,6 @@ """Support for HDMI CEC.""" -from collections import defaultdict +from __future__ import annotations + from functools import partial, reduce import logging import multiprocessing @@ -66,8 +67,6 @@ ICONS_BY_TYPE = { 5: ICON_AUDIO, } -CEC_DEVICES = defaultdict(list) - CMD_UP = "up" CMD_DOWN = "down" CMD_MUTE = "mute" @@ -134,7 +133,7 @@ SERVICE_POWER_ON = "power_on" SERVICE_STANDBY = "standby" # pylint: disable=unnecessary-lambda -DEVICE_SCHEMA = vol.Schema( +DEVICE_SCHEMA: vol.Schema = vol.Schema( { vol.All(cv.positive_int): vol.Any( lambda devices: DEVICE_SCHEMA(devices), cv.string @@ -376,7 +375,7 @@ class CecEntity(Entity): """Initialize the device.""" self._device = device self._icon = None - self._state = None + self._state: str | None = None self._logical_address = logical self.entity_id = "%s.%d" % (DOMAIN, self._logical_address) diff --git a/homeassistant/components/hdmi_cec/media_player.py b/homeassistant/components/hdmi_cec/media_player.py index c3cab6a8f98..1a5b3a6fc51 100644 --- a/homeassistant/components/hdmi_cec/media_player.py +++ b/homeassistant/components/hdmi_cec/media_player.py @@ -1,4 +1,6 @@ """Support for HDMI CEC devices as media players.""" +from __future__ import annotations + import logging from pycec.commands import CecCommand, KeyPressCommand, KeyReleaseCommand @@ -149,7 +151,7 @@ class CecPlayerEntity(CecEntity, MediaPlayerEntity): self.send_keypress(KEY_VOLUME_DOWN) @property - def state(self) -> str: + def state(self) -> str | None: """Cache state of device.""" return self._state diff --git a/homeassistant/components/hdmi_cec/switch.py b/homeassistant/components/hdmi_cec/switch.py index 5de38675fca..2ba606c9245 100644 --- a/homeassistant/components/hdmi_cec/switch.py +++ b/homeassistant/components/hdmi_cec/switch.py @@ -1,4 +1,6 @@ """Support for HDMI CEC devices as switches.""" +from __future__ import annotations + import logging from homeassistant.components.switch import DOMAIN, SwitchEntity @@ -56,7 +58,7 @@ class CecSwitchEntity(CecEntity, SwitchEntity): """Return True if entity is on.""" return self._state == STATE_ON - @property - def state(self) -> str: + @property # type: ignore + def state(self) -> str | None: """Return the cached state of device.""" return self._state diff --git a/mypy.ini b/mypy.ini index 8c5882b720d..a26926b4012 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1387,9 +1387,6 @@ ignore_errors = true [mypy-homeassistant.components.hassio.*] ignore_errors = true -[mypy-homeassistant.components.hdmi_cec.*] -ignore_errors = true - [mypy-homeassistant.components.here_travel_time.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 62da8b4fb5f..1b47ff8a16c 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -62,7 +62,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.habitica.*", "homeassistant.components.harmony.*", "homeassistant.components.hassio.*", - "homeassistant.components.hdmi_cec.*", "homeassistant.components.here_travel_time.*", "homeassistant.components.hisense_aehw4a1.*", "homeassistant.components.home_connect.*",