Add entity translations to Tellduslive (#98963)
This commit is contained in:
parent
fb6d19d08f
commit
a1b2b9a78c
7 changed files with 34 additions and 29 deletions
|
@ -34,6 +34,8 @@ async def async_setup_entry(
|
|||
class TelldusLiveSensor(TelldusLiveEntity, BinarySensorEntity):
|
||||
"""Representation of a Tellstick sensor."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
|
|
|
@ -35,6 +35,8 @@ async def async_setup_entry(
|
|||
class TelldusLiveCover(TelldusLiveEntity, CoverEntity):
|
||||
"""Representation of a cover."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool:
|
||||
"""Return the current position of the cover."""
|
||||
|
|
|
@ -9,7 +9,6 @@ from homeassistant.const import (
|
|||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_VIA_DEVICE,
|
||||
DEVICE_DEFAULT_NAME,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
|
@ -27,12 +26,12 @@ class TelldusLiveEntity(Entity):
|
|||
"""Base class for all Telldus Live entities."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, client, device_id):
|
||||
"""Initialize the entity."""
|
||||
self._id = device_id
|
||||
self._client = client
|
||||
self._name = self.device.name
|
||||
self._async_unsub_dispatcher_connect = None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
|
@ -50,8 +49,6 @@ class TelldusLiveEntity(Entity):
|
|||
@callback
|
||||
def _update_callback(self):
|
||||
"""Return the property of the device might have changed."""
|
||||
if self.device.name:
|
||||
self._name = self.device.name
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
|
@ -74,11 +71,6 @@ class TelldusLiveEntity(Entity):
|
|||
"""Return true if unable to access real state of entity."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return name of device."""
|
||||
return self._name or DEVICE_DEFAULT_NAME
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return true if device is not offline."""
|
||||
|
|
|
@ -37,6 +37,7 @@ async def async_setup_entry(
|
|||
class TelldusLiveLight(TelldusLiveEntity, LightEntity):
|
||||
"""Representation of a Tellstick Net light."""
|
||||
|
||||
_attr_name = None
|
||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||
|
||||
|
|
|
@ -43,80 +43,73 @@ SENSOR_TYPE_BAROMETRIC_PRESSURE = "barpress"
|
|||
SENSOR_TYPES: dict[str, SensorEntityDescription] = {
|
||||
SENSOR_TYPE_TEMPERATURE: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_HUMIDITY: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_RAINRATE: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_RAINRATE,
|
||||
name="Rain rate",
|
||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||
),
|
||||
SENSOR_TYPE_RAINTOTAL: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_RAINTOTAL,
|
||||
name="Rain total",
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SENSOR_TYPE_WINDDIRECTION: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_WINDDIRECTION,
|
||||
name="Wind direction",
|
||||
translation_key="wind_direction",
|
||||
),
|
||||
SENSOR_TYPE_WINDAVERAGE: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_WINDAVERAGE,
|
||||
name="Wind average",
|
||||
translation_key="wind_average",
|
||||
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
||||
device_class=SensorDeviceClass.WIND_SPEED,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_WINDGUST: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_WINDGUST,
|
||||
name="Wind gust",
|
||||
translation_key="wind_gust",
|
||||
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
||||
device_class=SensorDeviceClass.WIND_SPEED,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_UV: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_UV,
|
||||
name="UV",
|
||||
translation_key="uv",
|
||||
native_unit_of_measurement=UV_INDEX,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_WATT: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_WATT,
|
||||
name="Power",
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_LUMINANCE: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_LUMINANCE,
|
||||
name="Luminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_DEW_POINT: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_DEW_POINT,
|
||||
name="Dew Point",
|
||||
translation_key="dew_point",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SENSOR_TYPE_BAROMETRIC_PRESSURE: SensorEntityDescription(
|
||||
key=SENSOR_TYPE_BAROMETRIC_PRESSURE,
|
||||
name="Barometric Pressure",
|
||||
native_unit_of_measurement=UnitOfPressure.KPA,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -151,6 +144,8 @@ class TelldusLiveSensor(TelldusLiveEntity, SensorEntity):
|
|||
super().__init__(client, device_id)
|
||||
if desc := SENSOR_TYPES.get(self._type):
|
||||
self.entity_description = desc
|
||||
else:
|
||||
self._attr_name = None
|
||||
|
||||
@property
|
||||
def device_id(self):
|
||||
|
@ -182,14 +177,6 @@ class TelldusLiveSensor(TelldusLiveEntity, SensorEntity):
|
|||
"""Return the value as humidity."""
|
||||
return int(round(float(self._value)))
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
quantity_name = (
|
||||
self.entity_description.name if hasattr(self, "entity_description") else ""
|
||||
)
|
||||
return "{} {}".format(super().name, quantity_name or "").strip()
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
|
|
|
@ -21,5 +21,24 @@
|
|||
"title": "Pick endpoint."
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"wind_direction": {
|
||||
"name": "Wind direction"
|
||||
},
|
||||
"wind_average": {
|
||||
"name": "Wind average"
|
||||
},
|
||||
"wind_gust": {
|
||||
"name": "Wind gust"
|
||||
},
|
||||
"uv": {
|
||||
"name": "UV"
|
||||
},
|
||||
"dew_point": {
|
||||
"name": "Dew point"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ async def async_setup_entry(
|
|||
class TelldusLiveSwitch(TelldusLiveEntity, SwitchEntity):
|
||||
"""Representation of a Tellstick switch."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
|
|
Loading…
Add table
Reference in a new issue