Adds outside battery sensor
Adds an outside battery sensor to the integration, providing information about the battery level of the outdoor sensor. This includes: - Mapping the `t1bat` WSLink item to the `OUTSIDE_BATTERY` sensor. - Implementing logic to convert the battery level to a human-readable text representation and a corresponding icon. - Updates precipitation to intensity and fixes data type of battery levelpull/72/head^2
parent
fc8349c06e
commit
e10ea9901c
|
|
@ -144,6 +144,7 @@ REMAP_WSLINK_ITEMS: dict = {
|
|||
"t1rainyr": YEARLY_RAIN,
|
||||
"t234c2tem": CH3_TEMP,
|
||||
"t234c2hum": CH3_HUMIDITY,
|
||||
"t1bat": OUTSIDE_BATTERY,
|
||||
}
|
||||
|
||||
# TODO: Add more sensors
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from .const import (
|
|||
CHILL_INDEX,
|
||||
DOMAIN,
|
||||
HEAT_INDEX,
|
||||
OUTSIDE_BATTERY,
|
||||
OUTSIDE_HUMIDITY,
|
||||
OUTSIDE_TEMP,
|
||||
SENSORS_TO_LOAD,
|
||||
|
|
@ -26,7 +27,7 @@ from .const import (
|
|||
from .sensors_common import WeatherSensorEntityDescription
|
||||
from .sensors_weather import SENSOR_TYPES_WEATHER_API
|
||||
from .sensors_wslink import SENSOR_TYPES_WSLINK
|
||||
from .utils import chill_index, heat_index
|
||||
from .utils import chill_index, heat_index, battery_level_to_icon, battery_level_to_text
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -130,13 +131,27 @@ class WeatherSensor(
|
|||
):
|
||||
return self.entity_description.value_fn(chill_index(self.coordinator.data))
|
||||
|
||||
return None if self._data == "" else self.entity_description.value_fn(self._data)
|
||||
return (
|
||||
None if self._data == "" else self.entity_description.value_fn(self._data)
|
||||
)
|
||||
|
||||
@property
|
||||
def suggested_entity_id(self) -> str:
|
||||
"""Return name."""
|
||||
return generate_entity_id("sensor.{}", self.entity_description.key)
|
||||
|
||||
@property
|
||||
def icon(self) -> str | None:
|
||||
"""Return the dynamic icon for battery representation."""
|
||||
|
||||
if self.entity_description.key == OUTSIDE_BATTERY:
|
||||
try:
|
||||
return battery_level_to_icon(self.native_value)
|
||||
except Exception:
|
||||
return "mdi:battery-unknown"
|
||||
|
||||
return self.entity_description.icon
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Device info."""
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
WeatherSensorEntityDescription(
|
||||
key=RAIN,
|
||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
suggested_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||
suggested_display_precision=2,
|
||||
|
|
@ -307,8 +307,8 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
WeatherSensorEntityDescription(
|
||||
key=OUTSIDE_BATTERY,
|
||||
translation_key=OUTSIDE_BATTERY,
|
||||
icon=lambda data: battery_level_to_icon(battery_level_to_text(int(data))),
|
||||
icon="mdi:battery-unknown",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
value_fn=lambda data: battery_level_to_text(int(data)),
|
||||
value_fn=lambda data: battery_level_to_text(data),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ def battery_level_to_text(battery: int) -> UnitOfBat:
|
|||
return {
|
||||
0: UnitOfBat.LOW,
|
||||
1: UnitOfBat.NORMAL,
|
||||
}.get(battery, UnitOfBat.UNKNOWN)
|
||||
}.get(int(battery) if battery is not None else None, UnitOfBat.UNKNOWN)
|
||||
|
||||
|
||||
def battery_level_to_icon(battery: UnitOfBat) -> str:
|
||||
|
|
@ -202,7 +202,7 @@ def battery_level_to_icon(battery: UnitOfBat) -> str:
|
|||
"""
|
||||
|
||||
icons = {
|
||||
UnitOfBat.LOW: "mdi:battery-alert",
|
||||
UnitOfBat.LOW: "mdi:battery-low",
|
||||
UnitOfBat.NORMAL: "mdi:battery",
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue