Add entity translations to Sensibo (#96091)

This commit is contained in:
Joost Lekkerkerker 2023-07-08 16:50:46 +02:00 committed by GitHub
parent de211de598
commit 598610e313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 130 additions and 55 deletions

View File

@ -54,8 +54,8 @@ class SensiboDeviceBinarySensorEntityDescription(
FILTER_CLEAN_REQUIRED_DESCRIPTION = SensiboDeviceBinarySensorEntityDescription(
key="filter_clean",
translation_key="filter_clean",
device_class=BinarySensorDeviceClass.PROBLEM,
name="Filter clean required",
value_fn=lambda data: data.filter_clean,
)
@ -64,20 +64,18 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionBinarySensorEntityDescription, ...] = (
key="alive",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
name="Alive",
value_fn=lambda data: data.alive,
),
SensiboMotionBinarySensorEntityDescription(
key="is_main_sensor",
translation_key="is_main_sensor",
entity_category=EntityCategory.DIAGNOSTIC,
name="Main sensor",
icon="mdi:connection",
value_fn=lambda data: data.is_main_sensor,
),
SensiboMotionBinarySensorEntityDescription(
key="motion",
device_class=BinarySensorDeviceClass.MOTION,
name="Motion",
icon="mdi:motion-sensor",
value_fn=lambda data: data.motion,
),
@ -86,8 +84,8 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionBinarySensorEntityDescription, ...] = (
MOTION_DEVICE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
SensiboDeviceBinarySensorEntityDescription(
key="room_occupied",
translation_key="room_occupied",
device_class=BinarySensorDeviceClass.MOTION,
name="Room occupied",
icon="mdi:motion-sensor",
value_fn=lambda data: data.room_occupied,
),
@ -100,30 +98,30 @@ DEVICE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
SensiboDeviceBinarySensorEntityDescription(
key="pure_ac_integration",
translation_key="pure_ac_integration",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
name="Pure Boost linked with AC",
value_fn=lambda data: data.pure_ac_integration,
),
SensiboDeviceBinarySensorEntityDescription(
key="pure_geo_integration",
translation_key="pure_geo_integration",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
name="Pure Boost linked with presence",
value_fn=lambda data: data.pure_geo_integration,
),
SensiboDeviceBinarySensorEntityDescription(
key="pure_measure_integration",
translation_key="pure_measure_integration",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
name="Pure Boost linked with indoor air quality",
value_fn=lambda data: data.pure_measure_integration,
),
SensiboDeviceBinarySensorEntityDescription(
key="pure_prime_integration",
translation_key="pure_prime_integration",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
name="Pure Boost linked with outdoor air quality",
value_fn=lambda data: data.pure_prime_integration,
),
FILTER_CLEAN_REQUIRED_DESCRIPTION,

View File

@ -33,7 +33,7 @@ class SensiboButtonEntityDescription(
DEVICE_BUTTON_TYPES = SensiboButtonEntityDescription(
key="reset_filter",
name="Reset filter",
translation_key="reset_filter",
icon="mdi:air-filter",
entity_category=EntityCategory.CONFIG,
data_key="filter_clean",

View File

@ -49,6 +49,8 @@ def async_handle_api_call(
class SensiboBaseEntity(CoordinatorEntity[SensiboDataUpdateCoordinator]):
"""Representation of a Sensibo Base Entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: SensiboDataUpdateCoordinator,
@ -68,8 +70,6 @@ class SensiboBaseEntity(CoordinatorEntity[SensiboDataUpdateCoordinator]):
class SensiboDeviceBaseEntity(SensiboBaseEntity):
"""Representation of a Sensibo Device."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: SensiboDataUpdateCoordinator,
@ -93,8 +93,6 @@ class SensiboDeviceBaseEntity(SensiboBaseEntity):
class SensiboMotionBaseEntity(SensiboBaseEntity):
"""Representation of a Sensibo Motion Entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: SensiboDataUpdateCoordinator,

View File

@ -38,8 +38,8 @@ class SensiboNumberEntityDescription(
DEVICE_NUMBER_TYPES = (
SensiboNumberEntityDescription(
key="calibration_temp",
translation_key="calibration_temperature",
remote_key="temperature",
name="Temperature calibration",
icon="mdi:thermometer",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
@ -50,8 +50,8 @@ DEVICE_NUMBER_TYPES = (
),
SensiboNumberEntityDescription(
key="calibration_hum",
translation_key="calibration_humidity",
remote_key="humidity",
name="Humidity calibration",
icon="mdi:water",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,

View File

@ -41,7 +41,6 @@ DEVICE_SELECT_TYPES = (
SensiboSelectEntityDescription(
key="horizontalSwing",
data_key="horizontal_swing_mode",
name="Horizontal swing",
icon="mdi:air-conditioner",
value_fn=lambda data: data.horizontal_swing_mode,
options_fn=lambda data: data.horizontal_swing_modes,
@ -51,7 +50,6 @@ DEVICE_SELECT_TYPES = (
SensiboSelectEntityDescription(
key="light",
data_key="light_mode",
name="Light",
icon="mdi:flashlight",
value_fn=lambda data: data.light_mode,
options_fn=lambda data: data.light_modes,

View File

@ -67,8 +67,8 @@ class SensiboDeviceSensorEntityDescription(
FILTER_LAST_RESET_DESCRIPTION = SensiboDeviceSensorEntityDescription(
key="filter_last_reset",
translation_key="filter_last_reset",
device_class=SensorDeviceClass.TIMESTAMP,
name="Filter last reset",
icon="mdi:timer",
value_fn=lambda data: data.filter_last_reset,
extra_fn=None,
@ -77,22 +77,22 @@ FILTER_LAST_RESET_DESCRIPTION = SensiboDeviceSensorEntityDescription(
MOTION_SENSOR_TYPES: tuple[SensiboMotionSensorEntityDescription, ...] = (
SensiboMotionSensorEntityDescription(
key="rssi",
translation_key="rssi",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
state_class=SensorStateClass.MEASUREMENT,
name="rssi",
icon="mdi:wifi",
value_fn=lambda data: data.rssi,
entity_registry_enabled_default=False,
),
SensiboMotionSensorEntityDescription(
key="battery_voltage",
translation_key="battery_voltage",
device_class=SensorDeviceClass.VOLTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
name="Battery voltage",
icon="mdi:battery",
value_fn=lambda data: data.battery_voltage,
),
@ -101,7 +101,6 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
name="Humidity",
icon="mdi:water",
value_fn=lambda data: data.humidity,
),
@ -109,7 +108,6 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionSensorEntityDescription, ...] = (
key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
name="Temperature",
icon="mdi:thermometer",
value_fn=lambda data: data.temperature,
),
@ -120,18 +118,16 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
name="PM2.5",
icon="mdi:air-filter",
value_fn=lambda data: data.pm25,
extra_fn=None,
),
SensiboDeviceSensorEntityDescription(
key="pure_sensitivity",
name="Pure sensitivity",
translation_key="sensitivity",
icon="mdi:air-filter",
value_fn=lambda data: data.pure_sensitivity,
extra_fn=None,
translation_key="sensitivity",
),
FILTER_LAST_RESET_DESCRIPTION,
)
@ -139,35 +135,35 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
DEVICE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
SensiboDeviceSensorEntityDescription(
key="timer_time",
translation_key="timer_time",
device_class=SensorDeviceClass.TIMESTAMP,
name="Timer end time",
icon="mdi:timer",
value_fn=lambda data: data.timer_time,
extra_fn=lambda data: {"id": data.timer_id, "turn_on": data.timer_state_on},
),
SensiboDeviceSensorEntityDescription(
key="feels_like",
translation_key="feels_like",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
name="Temperature feels like",
value_fn=lambda data: data.feelslike,
extra_fn=None,
entity_registry_enabled_default=False,
),
SensiboDeviceSensorEntityDescription(
key="climate_react_low",
translation_key="climate_react_low",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
name="Climate React low temperature threshold",
value_fn=lambda data: data.smart_low_temp_threshold,
extra_fn=lambda data: data.smart_low_state,
entity_registry_enabled_default=False,
),
SensiboDeviceSensorEntityDescription(
key="climate_react_high",
translation_key="climate_react_high",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
name="Climate React high temperature threshold",
value_fn=lambda data: data.smart_high_temp_threshold,
extra_fn=lambda data: data.smart_high_state,
entity_registry_enabled_default=False,
@ -175,7 +171,6 @@ DEVICE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
SensiboDeviceSensorEntityDescription(
key="climate_react_type",
translation_key="smart_type",
name="Climate React type",
value_fn=lambda data: data.smart_type,
extra_fn=None,
entity_registry_enabled_default=False,
@ -186,19 +181,19 @@ DEVICE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
AIRQ_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
SensiboDeviceSensorEntityDescription(
key="airq_tvoc",
translation_key="airq_tvoc",
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:air-filter",
name="AirQ TVOC",
value_fn=lambda data: data.tvoc,
extra_fn=None,
),
SensiboDeviceSensorEntityDescription(
key="airq_co2",
translation_key="airq_co2",
device_class=SensorDeviceClass.CO2,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=SensorStateClass.MEASUREMENT,
name="AirQ CO2",
value_fn=lambda data: data.co2,
extra_fn=None,
),
@ -210,15 +205,14 @@ ELEMENT_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
name="PM 2.5",
value_fn=lambda data: data.pm25,
extra_fn=None,
),
SensiboDeviceSensorEntityDescription(
key="tvoc",
translation_key="tvoc",
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
state_class=SensorStateClass.MEASUREMENT,
name="TVOC",
value_fn=lambda data: data.tvoc,
extra_fn=None,
),
@ -227,7 +221,6 @@ ELEMENT_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.CO2,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=SensorStateClass.MEASUREMENT,
name="CO2",
value_fn=lambda data: data.co2,
extra_fn=None,
),
@ -243,7 +236,6 @@ ELEMENT_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
key="iaq",
device_class=SensorDeviceClass.AQI,
state_class=SensorStateClass.MEASUREMENT,
name="Air quality",
value_fn=lambda data: data.iaq,
extra_fn=None,
),

View File

@ -31,23 +31,45 @@
}
},
"entity": {
"sensor": {
"sensitivity": {
"state": {
"n": "Normal",
"s": "Sensitive"
}
"binary_sensor": {
"filter_clean": {
"name": "Filter clean required"
},
"smart_type": {
"state": {
"temperature": "Temperature",
"feelslike": "Feels like",
"humidity": "Humidity"
}
"is_main_sensor": {
"name": "Main sensor"
},
"room_occupied": {
"name": "Room occupied"
},
"pure_ac_integration": {
"name": "Pure Boost linked with AC"
},
"pure_geo_integration": {
"name": "Pure Boost linked with presence"
},
"pure_measure_integration": {
"name": "Pure Boost linked with indoor air quality"
},
"pure_prime_integration": {
"name": "Pure Boost linked with outdoor air quality"
}
},
"button": {
"reset_filter": {
"name": "Reset filter"
}
},
"number": {
"calibration_temperature": {
"name": "Temperature calibration"
},
"calibration_humidity": {
"name": "Humidity calibration"
}
},
"select": {
"horizontalswing": {
"name": "Horizontal swing",
"state": {
"stopped": "Stopped",
"fixedleft": "Fixed left",
@ -61,12 +83,79 @@
}
},
"light": {
"name": "Light",
"state": {
"on": "[%key:common::state::on%]",
"dim": "Dim",
"off": "[%key:common::state::off%]"
}
}
},
"sensor": {
"filter_last_reset": {
"name": "Filter last reset"
},
"rssi": {
"name": "RSSI"
},
"battery_voltage": {
"name": "Battery voltage"
},
"sensitivity": {
"name": "Pure sensitivity",
"state": {
"n": "Normal",
"s": "Sensitive"
}
},
"timer_time": {
"name": "Timer end time"
},
"feels_like": {
"name": "Temperature feels like"
},
"climate_react_low": {
"name": "Climate React low temperature threshold"
},
"climate_react_high": {
"name": "Climate React high temperature threshold"
},
"smart_type": {
"name": "Climate React type",
"state": {
"temperature": "Temperature",
"feelslike": "Feels like",
"humidity": "Humidity"
}
},
"airq_tvoc": {
"name": "AirQ TVOC"
},
"airq_co2": {
"name": "AirQ CO2"
},
"tvoc": {
"name": "TVOC"
},
"ethanol": {
"name": "Ethanol"
}
},
"switch": {
"timer_on_switch": {
"name": "Timer"
},
"climate_react_switch": {
"name": "Climate React"
},
"pure_boost_switch": {
"name": "Pure Boost"
}
},
"update": {
"fw_ver_available": {
"name": "Update available"
}
}
}
}

View File

@ -45,8 +45,8 @@ class SensiboDeviceSwitchEntityDescription(
DEVICE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
SensiboDeviceSwitchEntityDescription(
key="timer_on_switch",
translation_key="timer_on_switch",
device_class=SwitchDeviceClass.SWITCH,
name="Timer",
icon="mdi:timer",
value_fn=lambda data: data.timer_on,
extra_fn=lambda data: {"id": data.timer_id, "turn_on": data.timer_state_on},
@ -56,8 +56,8 @@ DEVICE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
),
SensiboDeviceSwitchEntityDescription(
key="climate_react_switch",
translation_key="climate_react_switch",
device_class=SwitchDeviceClass.SWITCH,
name="Climate React",
icon="mdi:wizard-hat",
value_fn=lambda data: data.smart_on,
extra_fn=lambda data: {"type": data.smart_type},
@ -70,8 +70,8 @@ DEVICE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
PURE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
SensiboDeviceSwitchEntityDescription(
key="pure_boost_switch",
translation_key="pure_boost_switch",
device_class=SwitchDeviceClass.SWITCH,
name="Pure Boost",
value_fn=lambda data: data.pure_boost_enabled,
extra_fn=None,
command_on="async_turn_on_off_pure_boost",

View File

@ -41,9 +41,9 @@ class SensiboDeviceUpdateEntityDescription(
DEVICE_SENSOR_TYPES: tuple[SensiboDeviceUpdateEntityDescription, ...] = (
SensiboDeviceUpdateEntityDescription(
key="fw_ver_available",
translation_key="fw_ver_available",
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.DIAGNOSTIC,
name="Update available",
icon="mdi:rocket-launch",
value_version=lambda data: data.fw_ver,
value_available=lambda data: data.fw_ver_available,

View File

@ -23,7 +23,7 @@ async def test_binary_sensor(
) -> None:
"""Test the Sensibo binary sensor."""
state1 = hass.states.get("binary_sensor.hallway_motion_sensor_alive")
state1 = hass.states.get("binary_sensor.hallway_motion_sensor_connectivity")
state2 = hass.states.get("binary_sensor.hallway_motion_sensor_main_sensor")
state3 = hass.states.get("binary_sensor.hallway_motion_sensor_motion")
state4 = hass.states.get("binary_sensor.hallway_room_occupied")
@ -57,7 +57,7 @@ async def test_binary_sensor(
)
await hass.async_block_till_done()
state1 = hass.states.get("binary_sensor.hallway_motion_sensor_alive")
state1 = hass.states.get("binary_sensor.hallway_motion_sensor_connectivity")
state3 = hass.states.get("binary_sensor.hallway_motion_sensor_motion")
assert state1.state == "off"
assert state3.state == "off"