Refactor some sensors and add translations to Overkiz (#64108)

This commit is contained in:
Mick Vleeshouwer 2022-01-17 12:47:42 -08:00 committed by GitHub
parent 8f6884ac10
commit b9cfaae3de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 128 additions and 11 deletions

View File

@ -43,3 +43,16 @@ OVERKIZ_DEVICE_TO_PLATFORM: dict[UIClass | UIWidget, Platform] = {
UIWidget.RTD_OUTDOOR_SIREN: Platform.SWITCH, # widgetName, uiClass is Siren (not supported)
UIClass.SWIMMING_POOL: Platform.SWITCH,
}
# Map Overkiz camelCase to Home Assistant snake_case for translation
OVERKIZ_STATE_TO_TRANSLATION: dict[str, str] = {
"externalGateway": "external_gateway",
"localUser": "local_user",
"lowBattery": "low_battery",
"LSC": "lsc",
"maintenanceRequired": "maintenance_required",
"noDefect": "no_defect",
"SAAC": "saac",
"SFC": "sfc",
"UPS": "ups",
}

View File

@ -102,10 +102,15 @@ class OverkizDescriptiveEntity(OverkizEntity):
self._attr_name = f"{super().name} {self.entity_description.name}"
# Used by translations of state and select sensors
# Used by state translations for sensor and select entities
@unique
class OverkizDeviceClass(StrEnum):
"""Device class for Overkiz specific devices."""
OPEN_CLOSED_PEDESTRIAN = "overkiz__open_closed_pedestrian"
BATTERY = "overkiz__battery"
DISCRETE_RSSI_LEVEL = "overkiz__discrete_rssi_level"
MEMORIZED_SIMPLE_VOLUME = "overkiz__memorized_simple_volume"
OPEN_CLOSED_PEDESTRIAN = "overkiz__open_closed_pedestrian"
PRIORITY_LOCK_ORIGINATOR = "overkiz__priority_lock_originator"
SENSOR_DEFECT = "overkiz__sensor_defect"
SENSOR_ROOM = "overkiz__sensor_room"

View File

@ -33,9 +33,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import HomeAssistantOverkizData
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES, OVERKIZ_STATE_TO_TRANSLATION
from .coordinator import OverkizDataUpdateCoordinator
from .entity import OverkizDescriptiveEntity, OverkizEntity
from .entity import OverkizDescriptiveEntity, OverkizDeviceClass, OverkizEntity
@dataclass
@ -53,12 +53,14 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
native_value=lambda value: int(str(value).strip("%")),
),
OverkizSensorDescription(
key=OverkizState.CORE_BATTERY,
name="Battery",
native_value=lambda value: str(value).capitalize(),
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:battery",
device_class=OverkizDeviceClass.BATTERY,
),
OverkizSensorDescription(
key=OverkizState.CORE_RSSI_LEVEL,
@ -309,15 +311,19 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
OverkizSensorDescription(
key=OverkizState.IO_SENSOR_ROOM,
name="Sensor Room",
native_value=lambda value: str(value).capitalize(),
entity_registry_enabled_default=False,
device_class=OverkizDeviceClass.SENSOR_ROOM,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:spray-bottle",
),
OverkizSensorDescription(
key=OverkizState.IO_PRIORITY_LOCK_ORIGINATOR,
name="Priority Lock Originator",
native_value=lambda value: str(value).capitalize(),
device_class=OverkizDeviceClass.PRIORITY_LOCK_ORIGINATOR,
icon="mdi:lock",
entity_registry_enabled_default=False,
native_value=lambda value: OVERKIZ_STATE_TO_TRANSLATION.get(
cast(str, value), cast(str, value)
),
),
OverkizSensorDescription(
key=OverkizState.CORE_PRIORITY_LOCK_TIMER,
@ -330,8 +336,19 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_DISCRETE_RSSI_LEVEL,
name="Discrete RSSI Level",
entity_registry_enabled_default=False,
native_value=lambda value: str(value).capitalize(),
entity_category=EntityCategory.DIAGNOSTIC,
device_class=OverkizDeviceClass.DISCRETE_RSSI_LEVEL,
icon="mdi:wifi",
),
OverkizSensorDescription(
key=OverkizState.CORE_SENSOR_DEFECT,
name="Sensor Defect",
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=OverkizDeviceClass.SENSOR_DEFECT,
native_value=lambda value: OVERKIZ_STATE_TO_TRANSLATION.get(
cast(str, value), cast(str, value)
),
),
# DomesticHotWaterProduction/WaterHeatingSystem
OverkizSensorDescription(

View File

@ -15,7 +15,7 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"server_in_maintenance": "Server is down for maintenance",
"too_many_requests": "Too many requests, try again later.",
"too_many_requests": "Too many requests, try again later",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {

View File

@ -0,0 +1,41 @@
{
"state": {
"overkiz__battery": {
"full": "Full",
"low": "Low",
"normal": "Normal",
"verylow": "Very low"
},
"overkiz__discrete_rssi_level": {
"good": "Good",
"low": "Low",
"normal": "Normal",
"verylow": "Very low"
},
"overkiz__priority_lock_originator": {
"lsc": "LSC",
"saac": "SAAC",
"sfc": "SFC",
"ups": "UPS",
"external_gateway": "External gateway",
"local_user": "Local user",
"myself": "Myself",
"rain": "Rain",
"security": "Security",
"temperature": "Temperature",
"timer": "Timer",
"user": "User",
"wind": "Wind"
},
"overkiz__sensor_room": {
"clean": "Clean",
"dirty": "Dirty"
},
"overkiz__sensor_defect": {
"dead": "Dead",
"low_battery": "Low battery",
"maintenance_required": "Maintenance required",
"no_defect": "No defect"
}
}
}

View File

@ -7,7 +7,7 @@
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"server_in_maintenance": "Server is down for maintenance",
"too_many_requests": "Too many requests, try again later.",
"too_many_requests": "Too many requests, try again later",
"unknown": "Unexpected error"
},
"step": {

View File

@ -0,0 +1,41 @@
{
"state": {
"overkiz__battery": {
"full": "Full",
"low": "Low",
"normal": "Normal",
"verylow": "Very low"
},
"overkiz__discrete_rssi_level": {
"good": "Good",
"low": "Low",
"normal": "Normal",
"verylow": "Very low"
},
"overkiz__priority_lock_originator": {
"external_gateway": "External gateway",
"local_user": "Local user",
"lsc": "LSC",
"myself": "Myself",
"rain": "Rain",
"saac": "SAAC",
"security": "Security",
"sfc": "SFC",
"temperature": "Temperature",
"timer": "Timer",
"ups": "UPS",
"user": "User",
"wind": "Wind"
},
"overkiz__sensor_defect": {
"dead": "Dead",
"low_battery": "Low battery",
"maintenance_required": "Maintenance required",
"no_defect": "No defect"
},
"overkiz__sensor_room": {
"clean": "Clean",
"dirty": "Dirty"
}
}
}