From 80909e88c07a34d03278494ac3588dd0e5acae5a Mon Sep 17 00:00:00 2001 From: schizza Date: Sun, 26 Oct 2025 20:59:57 +0100 Subject: [PATCH] Adds indoor and channel 2 battery sensors Adds support for displaying indoor console and channel 2 battery levels as sensors. Updates sensor logic to use a common list to determine icon representation Fixes #74 --- custom_components/sws12500/const.py | 23 ++++++++++++------- custom_components/sws12500/sensor.py | 3 ++- custom_components/sws12500/sensors_wslink.py | 18 +++++++++++++++ .../sws12500/translations/cs.json | 16 +++++++++++++ .../sws12500/translations/en.json | 16 +++++++++++++ 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/custom_components/sws12500/const.py b/custom_components/sws12500/const.py index afe1979..125db17 100644 --- a/custom_components/sws12500/const.py +++ b/custom_components/sws12500/const.py @@ -23,12 +23,8 @@ WSLINK: Final = "wslink" WINDY_API_KEY = "WINDY_API_KEY" WINDY_ENABLED: Final = "windy_enabled_checkbox" WINDY_LOGGER_ENABLED: Final = "windy_logger_checkbox" -WINDY_NOT_INSERTED: Final = ( - "Data was succefuly sent to Windy, but not inserted by Windy API. Does anyone else sent data to Windy?" -) -WINDY_INVALID_KEY: Final = ( - "Windy API KEY is invalid. Send data to Windy is now disabled. Check your API KEY and try again." -) +WINDY_NOT_INSERTED: Final = "Data was succefuly sent to Windy, but not inserted by Windy API. Does anyone else sent data to Windy?" +WINDY_INVALID_KEY: Final = "Windy API KEY is invalid. Send data to Windy is now disabled. Check your API KEY and try again." WINDY_SUCCESS: Final = ( "Windy successfully sent data and data was successfully inserted by Windy API" ) @@ -81,10 +77,12 @@ DAILY_RAIN: Final = "daily_rain" SOLAR_RADIATION: Final = "solar_radiation" INDOOR_TEMP: Final = "indoor_temp" INDOOR_HUMIDITY: Final = "indoor_humidity" +INDOOR_BATTERY: Final = "indoor_battery" UV: Final = "uv" CH2_TEMP: Final = "ch2_temp" CH2_HUMIDITY: Final = "ch2_humidity" CH2_CONNECTION: Final = "ch2_connection" +CH2_BATTERY: Final = "ch2_battery" CH3_TEMP: Final = "ch3_temp" CH3_HUMIDITY: Final = "ch3_humidity" CH3_CONNECTION: Final = "ch3_connection" @@ -95,7 +93,7 @@ HEAT_INDEX: Final = "heat_index" CHILL_INDEX: Final = "chill_index" -REMAP_ITEMS: dict = { +REMAP_ITEMS: dict[str, str] = { "baromin": BARO_PRESSURE, "tempf": OUTSIDE_TEMP, "dewptf": DEW_POINT, @@ -117,7 +115,7 @@ REMAP_ITEMS: dict = { "soilmoisture3": CH4_HUMIDITY, } -REMAP_WSLINK_ITEMS: dict = { +REMAP_WSLINK_ITEMS: dict[str, str] = { "intem": INDOOR_TEMP, "inhum": INDOOR_HUMIDITY, "t1tem": OUTSIDE_TEMP, @@ -145,6 +143,8 @@ REMAP_WSLINK_ITEMS: dict = { "t234c2tem": CH3_TEMP, "t234c2hum": CH3_HUMIDITY, "t1bat": OUTSIDE_BATTERY, + "inbat": INDOOR_BATTERY, + "t234c1bat": CH2_BATTERY, } # TODO: Add more sensors @@ -157,6 +157,7 @@ REMAP_WSLINK_ITEMS: dict = { DISABLED_BY_DEFAULT: Final = [ CH2_TEMP, CH2_HUMIDITY, + CH2_BATTERY, CH3_TEMP, CH3_HUMIDITY, CH4_TEMP, @@ -164,6 +165,12 @@ DISABLED_BY_DEFAULT: Final = [ OUTSIDE_BATTERY, ] +BATTERY_LIST = [ + OUTSIDE_BATTERY, + INDOOR_BATTERY, + CH2_BATTERY, +] + class UnitOfDir(StrEnum): """Wind direrction azimut.""" diff --git a/custom_components/sws12500/sensor.py b/custom_components/sws12500/sensor.py index 0be5eff..e252e0f 100644 --- a/custom_components/sws12500/sensor.py +++ b/custom_components/sws12500/sensor.py @@ -23,6 +23,7 @@ from .const import ( WIND_DIR, WIND_SPEED, WSLINK, + BATTERY_LIST, ) from .sensors_common import WeatherSensorEntityDescription from .sensors_weather import SENSOR_TYPES_WEATHER_API @@ -144,7 +145,7 @@ class WeatherSensor( def icon(self) -> str | None: """Return the dynamic icon for battery representation.""" - if self.entity_description.key == OUTSIDE_BATTERY: + if self.entity_description.key in BATTERY_LIST: try: return battery_level_to_icon(self.native_value) except Exception: diff --git a/custom_components/sws12500/sensors_wslink.py b/custom_components/sws12500/sensors_wslink.py index 91a712a..d46bd4a 100644 --- a/custom_components/sws12500/sensors_wslink.py +++ b/custom_components/sws12500/sensors_wslink.py @@ -19,6 +19,8 @@ from .const import ( BARO_PRESSURE, CH2_HUMIDITY, CH2_TEMP, + CH2_BATTERY, + INDOOR_BATTERY, CH3_HUMIDITY, CH3_TEMP, CH4_HUMIDITY, @@ -28,8 +30,10 @@ from .const import ( DEW_POINT, HEAT_INDEX, HOURLY_RAIN, + INDOOR_BATTERY, INDOOR_HUMIDITY, INDOOR_TEMP, + INDOOR_BATTERY, MONTHLY_RAIN, OUTSIDE_BATTERY, OUTSIDE_HUMIDITY, @@ -312,4 +316,18 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.ENUM, value_fn=lambda data: battery_level_to_text(data), ), + WeatherSensorEntityDescription( + key=CH2_BATTERY, + translation_key=CH2_BATTERY, + icon="mdi:battery-unknown", + device_class=SensorDeviceClass.ENUM, + value_fn=lambda data: battery_level_to_text(data), + ), + WeatherSensorEntityDescription( + key=INDOOR_BATTERY, + translation_key=INDOOR_BATTERY, + icon="mdi:battery-unknown", + device_class=SensorDeviceClass.ENUM, + value_fn=lambda data: battery_level_to_text(data), + ), ) diff --git a/custom_components/sws12500/translations/cs.json b/custom_components/sws12500/translations/cs.json index 8da9943..7208bf8 100644 --- a/custom_components/sws12500/translations/cs.json +++ b/custom_components/sws12500/translations/cs.json @@ -144,6 +144,22 @@ "normal": "Normální", "unknown": "Neznámá / zcela vybitá" } + }, + "indoor_battery": { + "name": "Stav nabití baterie kozole", + "state": { + "low": "Nízká", + "normal": "Normální", + "unknown": "Neznámá / zcela vybitá" + } + }, + "ch2_battery": { + "name": "Stav nabití baterie kanálu 2", + "state": { + "low": "Nízká", + "normal": "Normální", + "unknown": "Neznámá / zcela vybitá" + } } } }, diff --git a/custom_components/sws12500/translations/en.json b/custom_components/sws12500/translations/en.json index b0f3567..581bfde 100644 --- a/custom_components/sws12500/translations/en.json +++ b/custom_components/sws12500/translations/en.json @@ -144,6 +144,22 @@ "low": "Low", "unknown": "Unknown / drained out" } + }, + "ch2_battery": { + "name": "Channel 2 battery level", + "state": { + "normal": "OK", + "low": "Low", + "unknown": "Unknown / drained out" + } + }, + "indoor_battery": { + "name": "Console battery level", + "state": { + "normal": "OK", + "low": "Low", + "unknown": "Unknown / drained out" + } } } },