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