Add entity translations to Flo (#95347)

* Add entity translations to Flo

* Add entity translations to Flo
pull/95427/head
Joost Lekkerkerker 2023-06-28 08:36:10 +02:00 committed by GitHub
parent 4daacf9c4b
commit b53b162d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 23 deletions

View File

@ -45,10 +45,11 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
"""Binary sensor that reports on if there are any pending system alerts.""" """Binary sensor that reports on if there are any pending system alerts."""
_attr_device_class = BinarySensorDeviceClass.PROBLEM _attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_translation_key = "pending_system_alerts"
def __init__(self, device): def __init__(self, device):
"""Initialize the pending alerts binary sensor.""" """Initialize the pending alerts binary sensor."""
super().__init__("pending_system_alerts", "Pending system alerts", device) super().__init__("pending_system_alerts", device)
@property @property
def is_on(self): def is_on(self):
@ -71,10 +72,11 @@ class FloWaterDetectedBinarySensor(FloEntity, BinarySensorEntity):
"""Binary sensor that reports if water is detected (for leak detectors).""" """Binary sensor that reports if water is detected (for leak detectors)."""
_attr_device_class = BinarySensorDeviceClass.PROBLEM _attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_translation_key = "water_detected"
def __init__(self, device): def __init__(self, device):
"""Initialize the pending alerts binary sensor.""" """Initialize the pending alerts binary sensor."""
super().__init__("water_detected", "Water detected", device) super().__init__("water_detected", device)
@property @property
def is_on(self): def is_on(self):

View File

@ -20,12 +20,10 @@ class FloEntity(Entity):
def __init__( def __init__(
self, self,
entity_type: str, entity_type: str,
name: str,
device: FloDeviceDataUpdateCoordinator, device: FloDeviceDataUpdateCoordinator,
**kwargs, **kwargs,
) -> None: ) -> None:
"""Init Flo entity.""" """Init Flo entity."""
self._attr_name = name
self._attr_unique_id = f"{device.mac_address}_{entity_type}" self._attr_unique_id = f"{device.mac_address}_{entity_type}"
self._device: FloDeviceDataUpdateCoordinator = device self._device: FloDeviceDataUpdateCoordinator = device

View File

@ -22,14 +22,6 @@ from .entity import FloEntity
WATER_ICON = "mdi:water" WATER_ICON = "mdi:water"
GAUGE_ICON = "mdi:gauge" GAUGE_ICON = "mdi:gauge"
NAME_DAILY_USAGE = "Today's water usage"
NAME_CURRENT_SYSTEM_MODE = "Current system mode"
NAME_FLOW_RATE = "Water flow rate"
NAME_WATER_TEMPERATURE = "Water temperature"
NAME_AIR_TEMPERATURE = "Temperature"
NAME_WATER_PRESSURE = "Water pressure"
NAME_HUMIDITY = "Humidity"
NAME_BATTERY = "Battery"
async def async_setup_entry( async def async_setup_entry(
@ -46,7 +38,7 @@ async def async_setup_entry(
if device.device_type == "puck_oem": if device.device_type == "puck_oem":
entities.extend( entities.extend(
[ [
FloTemperatureSensor(NAME_AIR_TEMPERATURE, device), FloTemperatureSensor(device, False),
FloHumiditySensor(device), FloHumiditySensor(device),
FloBatterySensor(device), FloBatterySensor(device),
] ]
@ -57,7 +49,7 @@ async def async_setup_entry(
FloDailyUsageSensor(device), FloDailyUsageSensor(device),
FloSystemModeSensor(device), FloSystemModeSensor(device),
FloCurrentFlowRateSensor(device), FloCurrentFlowRateSensor(device),
FloTemperatureSensor(NAME_WATER_TEMPERATURE, device), FloTemperatureSensor(device, True),
FloPressureSensor(device), FloPressureSensor(device),
] ]
) )
@ -71,10 +63,11 @@ class FloDailyUsageSensor(FloEntity, SensorEntity):
_attr_native_unit_of_measurement = UnitOfVolume.GALLONS _attr_native_unit_of_measurement = UnitOfVolume.GALLONS
_attr_state_class: SensorStateClass = SensorStateClass.TOTAL_INCREASING _attr_state_class: SensorStateClass = SensorStateClass.TOTAL_INCREASING
_attr_device_class = SensorDeviceClass.WATER _attr_device_class = SensorDeviceClass.WATER
_attr_translation_key = "daily_consumption"
def __init__(self, device): def __init__(self, device):
"""Initialize the daily water usage sensor.""" """Initialize the daily water usage sensor."""
super().__init__("daily_consumption", NAME_DAILY_USAGE, device) super().__init__("daily_consumption", device)
self._state: float = None self._state: float = None
@property @property
@ -88,9 +81,11 @@ class FloDailyUsageSensor(FloEntity, SensorEntity):
class FloSystemModeSensor(FloEntity, SensorEntity): class FloSystemModeSensor(FloEntity, SensorEntity):
"""Monitors the current Flo system mode.""" """Monitors the current Flo system mode."""
_attr_translation_key = "current_system_mode"
def __init__(self, device): def __init__(self, device):
"""Initialize the system mode sensor.""" """Initialize the system mode sensor."""
super().__init__("current_system_mode", NAME_CURRENT_SYSTEM_MODE, device) super().__init__("current_system_mode", device)
self._state: str = None self._state: str = None
@property @property
@ -107,10 +102,11 @@ class FloCurrentFlowRateSensor(FloEntity, SensorEntity):
_attr_icon = GAUGE_ICON _attr_icon = GAUGE_ICON
_attr_native_unit_of_measurement = "gpm" _attr_native_unit_of_measurement = "gpm"
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_attr_translation_key = "current_flow_rate"
def __init__(self, device): def __init__(self, device):
"""Initialize the flow rate sensor.""" """Initialize the flow rate sensor."""
super().__init__("current_flow_rate", NAME_FLOW_RATE, device) super().__init__("current_flow_rate", device)
self._state: float = None self._state: float = None
@property @property
@ -128,9 +124,11 @@ class FloTemperatureSensor(FloEntity, SensorEntity):
_attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT _attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, name, device): def __init__(self, device, is_water):
"""Initialize the temperature sensor.""" """Initialize the temperature sensor."""
super().__init__("temperature", name, device) super().__init__("temperature", device)
if is_water:
self._attr_translation_key = "water_temperature"
self._state: float = None self._state: float = None
@property @property
@ -150,7 +148,7 @@ class FloHumiditySensor(FloEntity, SensorEntity):
def __init__(self, device): def __init__(self, device):
"""Initialize the humidity sensor.""" """Initialize the humidity sensor."""
super().__init__("humidity", NAME_HUMIDITY, device) super().__init__("humidity", device)
self._state: float = None self._state: float = None
@property @property
@ -167,10 +165,11 @@ class FloPressureSensor(FloEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.PRESSURE _attr_device_class = SensorDeviceClass.PRESSURE
_attr_native_unit_of_measurement = UnitOfPressure.PSI _attr_native_unit_of_measurement = UnitOfPressure.PSI
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_attr_translation_key = "water_pressure"
def __init__(self, device): def __init__(self, device):
"""Initialize the pressure sensor.""" """Initialize the pressure sensor."""
super().__init__("water_pressure", NAME_WATER_PRESSURE, device) super().__init__("water_pressure", device)
self._state: float = None self._state: float = None
@property @property
@ -190,7 +189,7 @@ class FloBatterySensor(FloEntity, SensorEntity):
def __init__(self, device): def __init__(self, device):
"""Initialize the battery sensor.""" """Initialize the battery sensor."""
super().__init__("battery", NAME_BATTERY, device) super().__init__("battery", device)
self._state: float = None self._state: float = None
@property @property

View File

@ -17,5 +17,37 @@
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]" "already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
} }
},
"entity": {
"binary_sensor": {
"pending_system_alerts": {
"name": "Pending system alerts"
},
"water_detected": {
"name": "Water detected"
}
},
"sensor": {
"daily_consumption": {
"name": "Today's water usage"
},
"current_system_mode": {
"name": "Current system mode"
},
"current_flow_rate": {
"name": "Water flow rate"
},
"water_temperature": {
"name": "Water temperature"
},
"water_pressure": {
"name": "Water pressure"
}
},
"switch": {
"shutoff_valve": {
"name": "Shutoff valve"
}
}
} }
} }

View File

@ -68,9 +68,11 @@ async def async_setup_entry(
class FloSwitch(FloEntity, SwitchEntity): class FloSwitch(FloEntity, SwitchEntity):
"""Switch class for the Flo by Moen valve.""" """Switch class for the Flo by Moen valve."""
_attr_translation_key = "shutoff_valve"
def __init__(self, device: FloDeviceDataUpdateCoordinator) -> None: def __init__(self, device: FloDeviceDataUpdateCoordinator) -> None:
"""Initialize the Flo switch.""" """Initialize the Flo switch."""
super().__init__("shutoff_valve", "Shutoff valve", device) super().__init__("shutoff_valve", device)
self._state = self._device.last_known_valve_state == "open" self._state = self._device.last_known_valve_state == "open"
@property @property