2019-10-18 00:04:27 +00:00
|
|
|
"""Shared schema code."""
|
2022-11-15 11:48:02 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-10-18 00:04:27 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-11-15 11:48:02 +00:00
|
|
|
from homeassistant.components.vacuum import VacuumEntityFeature
|
|
|
|
|
2022-10-29 08:22:59 +00:00
|
|
|
from ..const import CONF_SCHEMA
|
|
|
|
|
2019-10-18 00:04:27 +00:00
|
|
|
LEGACY = "legacy"
|
|
|
|
STATE = "state"
|
|
|
|
|
|
|
|
MQTT_VACUUM_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_SCHEMA, default=LEGACY): vol.All(
|
|
|
|
vol.Lower, vol.Any(LEGACY, STATE)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-15 11:48:02 +00:00
|
|
|
def services_to_strings(
|
2022-11-22 06:27:27 +00:00
|
|
|
services: VacuumEntityFeature,
|
2022-11-15 11:48:02 +00:00
|
|
|
service_to_string: dict[VacuumEntityFeature, str],
|
|
|
|
) -> list[str]:
|
2019-10-18 00:04:27 +00:00
|
|
|
"""Convert SUPPORT_* service bitmask to list of service strings."""
|
2022-11-15 11:48:02 +00:00
|
|
|
return [
|
|
|
|
service_to_string[service]
|
|
|
|
for service in service_to_string
|
|
|
|
if service & services
|
|
|
|
]
|
2019-10-18 00:04:27 +00:00
|
|
|
|
|
|
|
|
2022-11-15 11:48:02 +00:00
|
|
|
def strings_to_services(
|
|
|
|
strings: list[str], string_to_service: dict[str, VacuumEntityFeature]
|
2022-11-22 06:27:27 +00:00
|
|
|
) -> VacuumEntityFeature:
|
2019-10-18 00:04:27 +00:00
|
|
|
"""Convert service strings to SUPPORT_* service bitmask."""
|
2022-11-22 06:27:27 +00:00
|
|
|
services = VacuumEntityFeature(0)
|
2019-10-18 00:04:27 +00:00
|
|
|
for string in strings:
|
|
|
|
services |= string_to_service[string]
|
|
|
|
return services
|