Enforce VacuumEntityFeature (#82466)

pull/82567/head
epenet 2022-11-22 07:27:27 +01:00 committed by GitHub
parent 4134d722da
commit bf3c6e5f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 12 deletions

View File

@ -95,7 +95,7 @@ async def async_setup_platform(
DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES), DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES),
DemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES), DemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES),
DemoVacuum(DEMO_VACUUM_MINIMAL, SUPPORT_MINIMAL_SERVICES), DemoVacuum(DEMO_VACUUM_MINIMAL, SUPPORT_MINIMAL_SERVICES),
DemoVacuum(DEMO_VACUUM_NONE, 0), DemoVacuum(DEMO_VACUUM_NONE, VacuumEntityFeature(0)),
StateDemoVacuum(DEMO_VACUUM_STATE), StateDemoVacuum(DEMO_VACUUM_STATE),
] ]
) )
@ -106,9 +106,7 @@ class DemoVacuum(VacuumEntity):
_attr_should_poll = False _attr_should_poll = False
def __init__( def __init__(self, name: str, supported_features: VacuumEntityFeature) -> None:
self, name: str, supported_features: VacuumEntityFeature | int
) -> None:
"""Initialize the vacuum.""" """Initialize the vacuum."""
self._attr_name = name self._attr_name = name
self._attr_supported_features = supported_features self._attr_supported_features = supported_features

View File

@ -20,7 +20,7 @@ MQTT_VACUUM_SCHEMA = vol.Schema(
def services_to_strings( def services_to_strings(
services: VacuumEntityFeature | int, services: VacuumEntityFeature,
service_to_string: dict[VacuumEntityFeature, str], service_to_string: dict[VacuumEntityFeature, str],
) -> list[str]: ) -> list[str]:
"""Convert SUPPORT_* service bitmask to list of service strings.""" """Convert SUPPORT_* service bitmask to list of service strings."""
@ -33,9 +33,9 @@ def services_to_strings(
def strings_to_services( def strings_to_services(
strings: list[str], string_to_service: dict[str, VacuumEntityFeature] strings: list[str], string_to_service: dict[str, VacuumEntityFeature]
) -> VacuumEntityFeature | int: ) -> VacuumEntityFeature:
"""Convert service strings to SUPPORT_* service bitmask.""" """Convert service strings to SUPPORT_* service bitmask."""
services: VacuumEntityFeature | int = 0 services = VacuumEntityFeature(0)
for string in strings: for string in strings:
services |= string_to_service[string] services |= string_to_service[string]
return services return services

View File

@ -60,7 +60,7 @@ SERVICE_TO_STRING: dict[VacuumEntityFeature, str] = {
STRING_TO_SERVICE = {v: k for k, v in SERVICE_TO_STRING.items()} STRING_TO_SERVICE = {v: k for k, v in SERVICE_TO_STRING.items()}
DEFAULT_SERVICES: VacuumEntityFeature | int = ( DEFAULT_SERVICES = (
VacuumEntityFeature.START VacuumEntityFeature.START
| VacuumEntityFeature.STOP | VacuumEntityFeature.STOP
| VacuumEntityFeature.RETURN_HOME | VacuumEntityFeature.RETURN_HOME
@ -68,7 +68,7 @@ DEFAULT_SERVICES: VacuumEntityFeature | int = (
| VacuumEntityFeature.BATTERY | VacuumEntityFeature.BATTERY
| VacuumEntityFeature.CLEAN_SPOT | VacuumEntityFeature.CLEAN_SPOT
) )
ALL_SERVICES: VacuumEntityFeature | int = ( ALL_SERVICES = (
DEFAULT_SERVICES DEFAULT_SERVICES
| VacuumEntityFeature.PAUSE | VacuumEntityFeature.PAUSE
| VacuumEntityFeature.LOCATE | VacuumEntityFeature.LOCATE

View File

@ -180,10 +180,10 @@ class _BaseVacuum(Entity):
_attr_battery_level: int | None = None _attr_battery_level: int | None = None
_attr_fan_speed: str | None = None _attr_fan_speed: str | None = None
_attr_fan_speed_list: list[str] _attr_fan_speed_list: list[str]
_attr_supported_features: VacuumEntityFeature | int = 0 _attr_supported_features: VacuumEntityFeature = VacuumEntityFeature(0)
@property @property
def supported_features(self) -> VacuumEntityFeature | int: def supported_features(self) -> VacuumEntityFeature:
"""Flag vacuum cleaner features that are supported.""" """Flag vacuum cleaner features that are supported."""
return self._attr_supported_features return self._attr_supported_features

View File

@ -2396,7 +2396,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
), ),
TypeHintMatch( TypeHintMatch(
function_name="supported_features", function_name="supported_features",
return_type=["VacuumEntityFeature", "int"], return_type="VacuumEntityFeature",
), ),
TypeHintMatch( TypeHintMatch(
function_name="stop", function_name="stop",