Add entity name translations to Switchbot (#90600)

* Add entity name translations to Switchbot

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Apply suggestions from code review

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Fix tests

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Update homeassistant/components/switchbot/strings.json

Co-authored-by: Patrick ZAJDA <patrick@zajda.fr>

---------

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Patrick ZAJDA 2023-04-03 16:10:30 +02:00 committed by Paulus Schoutsen
parent 9f95da7793
commit 6cbf9288b5
4 changed files with 69 additions and 20 deletions

View File

@ -20,50 +20,50 @@ PARALLEL_UPDATES = 0
BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = { BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
"calibration": BinarySensorEntityDescription( "calibration": BinarySensorEntityDescription(
key="calibration", key="calibration",
name="Calibration", translation_key="calibration",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
"motion_detected": BinarySensorEntityDescription( "motion_detected": BinarySensorEntityDescription(
key="pir_state", key="pir_state",
name="Motion detected", translation_key="motion",
device_class=BinarySensorDeviceClass.MOTION, device_class=BinarySensorDeviceClass.MOTION,
), ),
"contact_open": BinarySensorEntityDescription( "contact_open": BinarySensorEntityDescription(
key="contact_open", key="contact_open",
name="Door open", translation_key="door_open",
device_class=BinarySensorDeviceClass.DOOR, device_class=BinarySensorDeviceClass.DOOR,
), ),
"contact_timeout": BinarySensorEntityDescription( "contact_timeout": BinarySensorEntityDescription(
key="contact_timeout", key="contact_timeout",
name="Door timeout", translation_key="door_timeout",
device_class=BinarySensorDeviceClass.PROBLEM, device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
"is_light": BinarySensorEntityDescription( "is_light": BinarySensorEntityDescription(
key="is_light", key="is_light",
name="Light", translation_key="light",
device_class=BinarySensorDeviceClass.LIGHT, device_class=BinarySensorDeviceClass.LIGHT,
), ),
"door_open": BinarySensorEntityDescription( "door_open": BinarySensorEntityDescription(
key="door_status", key="door_status",
name="Door status", translation_key="door_open",
device_class=BinarySensorDeviceClass.DOOR, device_class=BinarySensorDeviceClass.DOOR,
), ),
"unclosed_alarm": BinarySensorEntityDescription( "unclosed_alarm": BinarySensorEntityDescription(
key="unclosed_alarm", key="unclosed_alarm",
name="Door unclosed alarm", translation_key="door_unclosed_alarm",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.PROBLEM, device_class=BinarySensorDeviceClass.PROBLEM,
), ),
"unlocked_alarm": BinarySensorEntityDescription( "unlocked_alarm": BinarySensorEntityDescription(
key="unlocked_alarm", key="unlocked_alarm",
name="Door unlocked alarm", translation_key="door_unclosed_alarm",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.PROBLEM, device_class=BinarySensorDeviceClass.PROBLEM,
), ),
"auto_lock_paused": BinarySensorEntityDescription( "auto_lock_paused": BinarySensorEntityDescription(
key="auto_lock_paused", key="auto_lock_paused",
name="Door auto-lock paused", translation_key="door_auto_lock_paused",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
} }

View File

@ -28,7 +28,7 @@ PARALLEL_UPDATES = 0
SENSOR_TYPES: dict[str, SensorEntityDescription] = { SENSOR_TYPES: dict[str, SensorEntityDescription] = {
"rssi": SensorEntityDescription( "rssi": SensorEntityDescription(
key="rssi", key="rssi",
name="Bluetooth signal strength", translation_key="bluetooth_signal",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -37,7 +37,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
), ),
"wifi_rssi": SensorEntityDescription( "wifi_rssi": SensorEntityDescription(
key="wifi_rssi", key="wifi_rssi",
name="Wi-Fi signal strength", translation_key="wifi_signal",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -46,7 +46,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
), ),
"battery": SensorEntityDescription( "battery": SensorEntityDescription(
key="battery", key="battery",
name="Battery", translation_key="battery",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -54,27 +54,27 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
), ),
"lightLevel": SensorEntityDescription( "lightLevel": SensorEntityDescription(
key="lightLevel", key="lightLevel",
name="Light level", translation_key="light_level",
native_unit_of_measurement="Level", native_unit_of_measurement="Level",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
"humidity": SensorEntityDescription( "humidity": SensorEntityDescription(
key="humidity", key="humidity",
name="Humidity", translation_key="humidity",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
), ),
"temperature": SensorEntityDescription( "temperature": SensorEntityDescription(
key="temperature", key="temperature",
name="Temperature", translation_key="temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
), ),
"power": SensorEntityDescription( "power": SensorEntityDescription(
key="power", key="power",
name="Power", translation_key="power",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,

View File

@ -58,5 +58,56 @@
} }
} }
} }
},
"entity": {
"binary_sensor": {
"calibration": {
"name": "Calibration"
},
"motion": {
"name": "[%key:component::binary_sensor::entity_component::motion::name%]"
},
"door_open": {
"name": "[%key:component::binary_sensor::entity_component::door::name%]"
},
"door_timeout": {
"name": "Timeout"
},
"light": {
"name": "[%key:component::binary_sensor::entity_component::light::name%]"
},
"door_unclosed_alarm": {
"name": "Unclosed alarm"
},
"door_unlocked_alarm": {
"name": "Unlocked alarm"
},
"door_auto_lock_paused": {
"name": "Auto-lock paused"
}
},
"sensor": {
"bluetooth_signal": {
"name": "Bluetooth signal"
},
"wifi_signal": {
"name": "Wi-Fi signal"
},
"battery": {
"name": "[%key:component::sensor::entity_component::battery::name%]"
},
"light_level": {
"name": "Light level"
},
"humidity": {
"name": "[%key:component::sensor::entity_component::humidity::name%]"
},
"temperature": {
"name": "[%key:component::sensor::entity_component::temperature::name%]"
},
"power": {
"name": "[%key:component::sensor::entity_component::power::name%]"
}
}
} }
} }

View File

@ -50,12 +50,10 @@ async def test_sensors(
assert battery_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "%" assert battery_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "%"
assert battery_sensor_attrs[ATTR_STATE_CLASS] == "measurement" assert battery_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal_strength") rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal")
rssi_sensor_attrs = rssi_sensor.attributes rssi_sensor_attrs = rssi_sensor.attributes
assert rssi_sensor.state == "-60" assert rssi_sensor.state == "-60"
assert ( assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal"
rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal strength"
)
assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm" assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm"
assert await hass.config_entries.async_unload(entry.entry_id) assert await hass.config_entries.async_unload(entry.entry_id)