From bf3c6e5f58b7a42d8e4c9784b41c664f2f047f84 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 22 Nov 2022 07:27:27 +0100 Subject: [PATCH] Enforce VacuumEntityFeature (#82466) --- homeassistant/components/demo/vacuum.py | 6 ++---- homeassistant/components/mqtt/vacuum/schema.py | 6 +++--- homeassistant/components/mqtt/vacuum/schema_state.py | 4 ++-- homeassistant/components/vacuum/__init__.py | 4 ++-- pylint/plugins/hass_enforce_type_hints.py | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/demo/vacuum.py b/homeassistant/components/demo/vacuum.py index 5426c61fa52..c283ab5456f 100644 --- a/homeassistant/components/demo/vacuum.py +++ b/homeassistant/components/demo/vacuum.py @@ -95,7 +95,7 @@ async def async_setup_platform( DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES), DemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES), DemoVacuum(DEMO_VACUUM_MINIMAL, SUPPORT_MINIMAL_SERVICES), - DemoVacuum(DEMO_VACUUM_NONE, 0), + DemoVacuum(DEMO_VACUUM_NONE, VacuumEntityFeature(0)), StateDemoVacuum(DEMO_VACUUM_STATE), ] ) @@ -106,9 +106,7 @@ class DemoVacuum(VacuumEntity): _attr_should_poll = False - def __init__( - self, name: str, supported_features: VacuumEntityFeature | int - ) -> None: + def __init__(self, name: str, supported_features: VacuumEntityFeature) -> None: """Initialize the vacuum.""" self._attr_name = name self._attr_supported_features = supported_features diff --git a/homeassistant/components/mqtt/vacuum/schema.py b/homeassistant/components/mqtt/vacuum/schema.py index 20b7bced99d..78175f61255 100644 --- a/homeassistant/components/mqtt/vacuum/schema.py +++ b/homeassistant/components/mqtt/vacuum/schema.py @@ -20,7 +20,7 @@ MQTT_VACUUM_SCHEMA = vol.Schema( def services_to_strings( - services: VacuumEntityFeature | int, + services: VacuumEntityFeature, service_to_string: dict[VacuumEntityFeature, str], ) -> list[str]: """Convert SUPPORT_* service bitmask to list of service strings.""" @@ -33,9 +33,9 @@ def services_to_strings( def strings_to_services( strings: list[str], string_to_service: dict[str, VacuumEntityFeature] -) -> VacuumEntityFeature | int: +) -> VacuumEntityFeature: """Convert service strings to SUPPORT_* service bitmask.""" - services: VacuumEntityFeature | int = 0 + services = VacuumEntityFeature(0) for string in strings: services |= string_to_service[string] return services diff --git a/homeassistant/components/mqtt/vacuum/schema_state.py b/homeassistant/components/mqtt/vacuum/schema_state.py index 2bacf4f36de..a854d3b0620 100644 --- a/homeassistant/components/mqtt/vacuum/schema_state.py +++ b/homeassistant/components/mqtt/vacuum/schema_state.py @@ -60,7 +60,7 @@ SERVICE_TO_STRING: dict[VacuumEntityFeature, str] = { STRING_TO_SERVICE = {v: k for k, v in SERVICE_TO_STRING.items()} -DEFAULT_SERVICES: VacuumEntityFeature | int = ( +DEFAULT_SERVICES = ( VacuumEntityFeature.START | VacuumEntityFeature.STOP | VacuumEntityFeature.RETURN_HOME @@ -68,7 +68,7 @@ DEFAULT_SERVICES: VacuumEntityFeature | int = ( | VacuumEntityFeature.BATTERY | VacuumEntityFeature.CLEAN_SPOT ) -ALL_SERVICES: VacuumEntityFeature | int = ( +ALL_SERVICES = ( DEFAULT_SERVICES | VacuumEntityFeature.PAUSE | VacuumEntityFeature.LOCATE diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index 708c511a85c..cf82836cbec 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -180,10 +180,10 @@ class _BaseVacuum(Entity): _attr_battery_level: int | None = None _attr_fan_speed: str | None = None _attr_fan_speed_list: list[str] - _attr_supported_features: VacuumEntityFeature | int = 0 + _attr_supported_features: VacuumEntityFeature = VacuumEntityFeature(0) @property - def supported_features(self) -> VacuumEntityFeature | int: + def supported_features(self) -> VacuumEntityFeature: """Flag vacuum cleaner features that are supported.""" return self._attr_supported_features diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index b7219bbf0e4..a60b1c7de85 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -2396,7 +2396,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { ), TypeHintMatch( function_name="supported_features", - return_type=["VacuumEntityFeature", "int"], + return_type="VacuumEntityFeature", ), TypeHintMatch( function_name="stop",