Compare commits
49 Commits
6eceee1f4e
...
f7cea43722
| Author | SHA1 | Date |
|---|---|---|
|
|
f7cea43722 | |
|
|
7ff8bb7f92 | |
|
|
dbebc501e3 | |
|
|
8247f2b854 | |
|
|
d48f0fda6e | |
|
|
99fd6d266c | |
|
|
64dd47a3e9 | |
|
|
720c2148e6 | |
|
|
b858f648b9 | |
|
|
07ca4a6833 | |
|
|
de013891c0 | |
|
|
0d0922a494 | |
|
|
af19358ac7 | |
|
|
3dbf8b8a7a | |
|
|
a68a4c929a | |
|
|
af286648e9 | |
|
|
b6080fe9fd | |
|
|
a07af5a4fd | |
|
|
f14e6500d4 | |
|
|
a1f2bf10ea | |
|
|
e10ea9901c | |
|
|
fc8349c06e | |
|
|
d4d2440ae8 | |
|
|
827fb71e25 | |
|
|
2d758835dc | |
|
|
0027a80968 | |
|
|
e11e068c0f | |
|
|
1ecd88269d | |
|
|
09d79e2032 | |
|
|
bbe31da4c5 | |
|
|
68da7aad98 | |
|
|
de8d2a7b0c | |
|
|
cf0938a6fd | |
|
|
4d2dedbb11 | |
|
|
feed730818 | |
|
|
b1cec2f38f | |
|
|
99d25bfd56 | |
|
|
af87fd0719 | |
|
|
0ab5321170 | |
|
|
fdcd28f96a | |
|
|
093a7915f0 | |
|
|
ea0a5e34e3 | |
|
|
fdd4cacddf | |
|
|
601d1f3984 | |
|
|
287e74673e | |
|
|
397e44e5f2 | |
|
|
f9d80d7a00 | |
|
|
2b57eeb4fa | |
|
|
dc5c45483e |
|
|
@ -0,0 +1,5 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: schizza
|
||||
ko_fi: schizza
|
||||
buy_me_a_coffee: schizza
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Logs**
|
||||
Provide `Developer log` if applicable
|
||||
|
||||
**Provide information about your station:**
|
||||
- Weather station type:
|
||||
- firmware version:
|
||||
|
||||
- [ ] Using PWS protocol
|
||||
- [ ] Using WSLink API
|
||||
- [ ] Using WSLink proxy Add-on
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
|
@ -0,0 +1 @@
|
|||
blank_issues_enabled: false
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is.
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Is your feature request a new addition**
|
||||
Describe what you want to achieve. How new feature should work.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
name: Issue
|
||||
about: A minor issue that does not significantly affect functionality.
|
||||
title: "[ISSUE]"
|
||||
labels: issue
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the issue**
|
||||
A clear and concise description of what the issue is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior if any:
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Logs**
|
||||
Provide `Developer log` if applicable
|
||||
|
||||
**Provide information about your station:**
|
||||
- Weather station type:
|
||||
- firmware version:
|
||||
|
||||
- [ ] Using PWS protocol
|
||||
- [ ] Using WSLink API
|
||||
- [ ] Using WSLink proxy Add-on
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
|
@ -7,7 +7,6 @@ import voluptuous as vol
|
|||
from homeassistant.config_entries import ConfigFlow, OptionsFlow
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from .utils import long_term_units_in_statistics_meta, migrate_data
|
||||
|
||||
from .const import (
|
||||
API_ID,
|
||||
|
|
@ -16,7 +15,6 @@ from .const import (
|
|||
DOMAIN,
|
||||
INVALID_CREDENTIALS,
|
||||
SENSORS_TO_LOAD,
|
||||
SENSOR_TO_MIGRATE,
|
||||
WINDY_API_KEY,
|
||||
WINDY_ENABLED,
|
||||
WINDY_LOGGER_ENABLED,
|
||||
|
|
@ -41,7 +39,7 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
|
||||
self.windy_data: dict[str, Any] = {}
|
||||
self.windy_data_schema = {}
|
||||
self.user_data: dict[str, str] = {}
|
||||
self.user_data: dict[str, Any] = {}
|
||||
self.user_data_schema = {}
|
||||
self.sensors: dict[str, Any] = {}
|
||||
self.migrate_schema = {}
|
||||
|
|
@ -50,7 +48,7 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
def config_entry(self):
|
||||
return self.hass.config_entries.async_get_entry(self.handler)
|
||||
|
||||
def _get_entry_data(self):
|
||||
async def _get_entry_data(self):
|
||||
"""Get entry data."""
|
||||
|
||||
self.user_data: dict[str, Any] = {
|
||||
|
|
@ -61,16 +59,18 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
}
|
||||
|
||||
self.user_data_schema = {
|
||||
vol.Required(API_ID, default=self.user_data[API_ID] or ""): str,
|
||||
vol.Required(API_KEY, default=self.user_data[API_KEY] or ""): str,
|
||||
vol.Optional(WSLINK, default=self.user_data[WSLINK]): bool or False,
|
||||
vol.Optional(DEV_DBG, default=self.user_data[DEV_DBG]): bool or False,
|
||||
vol.Required(API_ID, default=self.user_data.get(API_ID, "")): str,
|
||||
vol.Required(API_KEY, default=self.user_data.get(API_KEY, "")): str,
|
||||
vol.Optional(WSLINK, default=self.user_data.get(WSLINK, False)): bool,
|
||||
vol.Optional(DEV_DBG, default=self.user_data.get(DEV_DBG, False)): bool,
|
||||
}
|
||||
|
||||
self.sensors: dict[str, Any] = {
|
||||
SENSORS_TO_LOAD: self.config_entry.options.get(SENSORS_TO_LOAD)
|
||||
if isinstance(self.config_entry.options.get(SENSORS_TO_LOAD), list)
|
||||
else []
|
||||
SENSORS_TO_LOAD: (
|
||||
self.config_entry.options.get(SENSORS_TO_LOAD)
|
||||
if isinstance(self.config_entry.options.get(SENSORS_TO_LOAD), list)
|
||||
else []
|
||||
)
|
||||
}
|
||||
|
||||
self.windy_data: dict[str, Any] = {
|
||||
|
|
@ -83,34 +83,26 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
|
||||
self.windy_data_schema = {
|
||||
vol.Optional(
|
||||
WINDY_API_KEY, default=self.windy_data[WINDY_API_KEY] or ""
|
||||
WINDY_API_KEY, default=self.windy_data.get(WINDY_API_KEY, "")
|
||||
): str,
|
||||
vol.Optional(WINDY_ENABLED, default=self.windy_data[WINDY_ENABLED]): bool
|
||||
or False,
|
||||
vol.Optional(
|
||||
WINDY_LOGGER_ENABLED,
|
||||
default=self.windy_data[WINDY_LOGGER_ENABLED],
|
||||
): bool or False,
|
||||
}
|
||||
|
||||
self.migrate_schema = {
|
||||
vol.Required(SENSOR_TO_MIGRATE): vol.In(
|
||||
long_term_units_in_statistics_meta() or {}
|
||||
),
|
||||
vol.Optional("trigger_action", default=False): bool,
|
||||
): bool
|
||||
or False,
|
||||
}
|
||||
|
||||
async def async_step_init(self, user_input=None):
|
||||
"""Manage the options - show menu first."""
|
||||
return self.async_show_menu(
|
||||
step_id="init", menu_options=["basic", "windy", "migration"]
|
||||
)
|
||||
return self.async_show_menu(step_id="init", menu_options=["basic", "windy"])
|
||||
|
||||
async def async_step_basic(self, user_input=None):
|
||||
"""Manage basic options - credentials."""
|
||||
errors = {}
|
||||
|
||||
self._get_entry_data()
|
||||
await self._get_entry_data()
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
|
|
@ -147,7 +139,7 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
"""Manage windy options."""
|
||||
errors = {}
|
||||
|
||||
self._get_entry_data()
|
||||
await self._get_entry_data()
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
|
|
@ -160,7 +152,7 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
errors[WINDY_API_KEY] = "windy_key_required"
|
||||
return self.async_show_form(
|
||||
step_id="windy",
|
||||
data_schema=self.windy_data_schema,
|
||||
data_schema=vol.Schema(self.windy_data_schema),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
|
|
@ -172,51 +164,6 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
async def async_step_migration(self, user_input=None):
|
||||
"""Migrate sensors."""
|
||||
|
||||
# hj
|
||||
errors = {}
|
||||
|
||||
self._get_entry_data()
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="migration",
|
||||
data_schema=vol.Schema(self.migrate_schema),
|
||||
errors=errors,
|
||||
description_placeholders={
|
||||
"migration_status": "-",
|
||||
"migration_count": "-",
|
||||
},
|
||||
)
|
||||
|
||||
if user_input.get("trigger_action"):
|
||||
# Akce se vykoná po zaškrtnutí
|
||||
count = await self.hass.async_add_executor_job(
|
||||
migrate_data, user_input.get(SENSOR_TO_MIGRATE)
|
||||
)
|
||||
return self.async_show_form(
|
||||
step_id="migration",
|
||||
data_schema=vol.Schema(self.migrate_schema),
|
||||
errors=errors,
|
||||
description_placeholders={
|
||||
"migration_status": user_input.get(SENSOR_TO_MIGRATE),
|
||||
"migration_count": count,
|
||||
},
|
||||
)
|
||||
|
||||
# retain windy data
|
||||
user_input.update(self.windy_data)
|
||||
|
||||
# retain user_data
|
||||
user_input.update(self.user_data)
|
||||
|
||||
# retain senors
|
||||
user_input.update(self.sensors)
|
||||
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
|
||||
class ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Sencor SWS 12500 Weather Station."""
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@ 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"
|
||||
)
|
||||
|
|
@ -63,11 +67,16 @@ OUTSIDE_TEMP: Final = "outside_temp"
|
|||
DEW_POINT: Final = "dew_point"
|
||||
OUTSIDE_HUMIDITY: Final = "outside_humidity"
|
||||
OUTSIDE_CONNECTION: Final = "outside_connection"
|
||||
OUTSIDE_BATTERY: Final = "outside_battery"
|
||||
WIND_SPEED: Final = "wind_speed"
|
||||
WIND_GUST: Final = "wind_gust"
|
||||
WIND_DIR: Final = "wind_dir"
|
||||
WIND_AZIMUT: Final = "wind_azimut"
|
||||
RAIN: Final = "rain"
|
||||
HOURLY_RAIN: Final = "hourly_rain"
|
||||
WEEKLY_RAIN: Final = "weekly_rain"
|
||||
MONTHLY_RAIN: Final = "monthly_rain"
|
||||
YEARLY_RAIN: Final = "yearly_rain"
|
||||
DAILY_RAIN: Final = "daily_rain"
|
||||
SOLAR_RADIATION: Final = "solar_radiation"
|
||||
INDOOR_TEMP: Final = "indoor_temp"
|
||||
|
|
@ -129,15 +138,18 @@ REMAP_WSLINK_ITEMS: dict = {
|
|||
"t234c2cn": CH3_CONNECTION,
|
||||
"t1chill": CHILL_INDEX,
|
||||
"t1heat": HEAT_INDEX,
|
||||
"t1rainhr": HOURLY_RAIN,
|
||||
"t1rainwy": WEEKLY_RAIN,
|
||||
"t1rainmth": MONTHLY_RAIN,
|
||||
"t1rainyr": YEARLY_RAIN,
|
||||
"t234c2tem": CH3_TEMP,
|
||||
"t234c2hum": CH3_HUMIDITY,
|
||||
"t1bat": OUTSIDE_BATTERY,
|
||||
}
|
||||
|
||||
# TODO: Add more sensors
|
||||
#
|
||||
# 'inbat' indoor battery level (1 normal, 0 low)
|
||||
# 't1rainhr' hourly rain rate in mm
|
||||
# 't1rainwy' weekly rain rate in mm
|
||||
# 't1rainmth': monthly rain rate in mm
|
||||
# 't1rainyr': yearly rain rate in mm
|
||||
# 't1bat': outdoor battery level (1 normal, 0 low)
|
||||
# 't234c1bat': CH2 battery level (1 normal, 0 low) CH2 in integration is CH1 in WSLink
|
||||
|
||||
|
|
@ -149,6 +161,7 @@ DISABLED_BY_DEFAULT: Final = [
|
|||
CH3_HUMIDITY,
|
||||
CH4_TEMP,
|
||||
CH4_HUMIDITY,
|
||||
OUTSIDE_BATTERY,
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -191,3 +204,18 @@ AZIMUT: list[UnitOfDir] = [
|
|||
UnitOfDir.NNW,
|
||||
UnitOfDir.N,
|
||||
]
|
||||
|
||||
|
||||
class UnitOfBat(StrEnum):
|
||||
"""Battery level unit of measure."""
|
||||
|
||||
LOW = "low"
|
||||
NORMAL = "normal"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
BATTERY_LEVEL: list[UnitOfBat] = [
|
||||
UnitOfBat.LOW,
|
||||
UnitOfBat.NORMAL,
|
||||
UnitOfBat.UNKNOWN,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@
|
|||
"issue_tracker": "https://github.com/schizza/SWS-12500-custom-component/issues",
|
||||
"requirements": [],
|
||||
"ssdp": [],
|
||||
"version": "1.5.3",
|
||||
"version": "1.6.6",
|
||||
"zeroconf": []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -27,21 +27,26 @@ from .const import (
|
|||
DAILY_RAIN,
|
||||
DEW_POINT,
|
||||
HEAT_INDEX,
|
||||
HOURLY_RAIN,
|
||||
INDOOR_HUMIDITY,
|
||||
INDOOR_TEMP,
|
||||
MONTHLY_RAIN,
|
||||
OUTSIDE_BATTERY,
|
||||
OUTSIDE_HUMIDITY,
|
||||
OUTSIDE_TEMP,
|
||||
RAIN,
|
||||
SOLAR_RADIATION,
|
||||
UV,
|
||||
WEEKLY_RAIN,
|
||||
WIND_AZIMUT,
|
||||
WIND_DIR,
|
||||
WIND_GUST,
|
||||
WIND_SPEED,
|
||||
YEARLY_RAIN,
|
||||
UnitOfDir,
|
||||
)
|
||||
from .sensors_common import WeatherSensorEntityDescription
|
||||
from .utils import wind_dir_to_text
|
||||
from .utils import battery_level_to_icon, battery_level_to_text, wind_dir_to_text
|
||||
|
||||
SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||
WeatherSensorEntityDescription(
|
||||
|
|
@ -139,10 +144,10 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=RAIN,
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
suggested_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||
suggested_display_precision=2,
|
||||
icon="mdi:weather-pouring",
|
||||
translation_key=RAIN,
|
||||
|
|
@ -159,6 +164,50 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
translation_key=DAILY_RAIN,
|
||||
value_fn=lambda data: cast("float", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=HOURLY_RAIN,
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
suggested_display_precision=2,
|
||||
icon="mdi:weather-pouring",
|
||||
translation_key=HOURLY_RAIN,
|
||||
value_fn=lambda data: cast("float", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=WEEKLY_RAIN,
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
suggested_display_precision=2,
|
||||
icon="mdi:weather-pouring",
|
||||
translation_key=WEEKLY_RAIN,
|
||||
value_fn=lambda data: cast("float", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=MONTHLY_RAIN,
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
suggested_display_precision=2,
|
||||
icon="mdi:weather-pouring",
|
||||
translation_key=MONTHLY_RAIN,
|
||||
value_fn=lambda data: cast("float", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=YEARLY_RAIN,
|
||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
device_class=SensorDeviceClass.PRECIPITATION,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
suggested_display_precision=2,
|
||||
icon="mdi:weather-pouring",
|
||||
translation_key=YEARLY_RAIN,
|
||||
value_fn=lambda data: cast("float", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=SOLAR_RADIATION,
|
||||
native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
|
||||
|
|
@ -196,25 +245,25 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
translation_key=CH2_HUMIDITY,
|
||||
value_fn=lambda data: cast("int", data),
|
||||
),
|
||||
# WeatherSensorEntityDescription(
|
||||
# key=CH3_TEMP,
|
||||
# native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||
# state_class=SensorStateClass.MEASUREMENT,
|
||||
# device_class=SensorDeviceClass.TEMPERATURE,
|
||||
# suggested_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
# icon="mdi:weather-sunny",
|
||||
# translation_key=CH3_TEMP,
|
||||
# value_fn=lambda data: cast(float, data),
|
||||
# ),
|
||||
# WeatherSensorEntityDescription(
|
||||
# key=CH3_HUMIDITY,
|
||||
# native_unit_of_measurement=PERCENTAGE,
|
||||
# state_class=SensorStateClass.MEASUREMENT,
|
||||
# device_class=SensorDeviceClass.HUMIDITY,
|
||||
# icon="mdi:weather-sunny",
|
||||
# translation_key=CH3_HUMIDITY,
|
||||
# value_fn=lambda data: cast(int, data),
|
||||
# ),
|
||||
WeatherSensorEntityDescription(
|
||||
key=CH3_TEMP,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
suggested_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
icon="mdi:weather-sunny",
|
||||
translation_key=CH3_TEMP,
|
||||
value_fn=lambda data: cast(float, data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=CH3_HUMIDITY,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
icon="mdi:weather-sunny",
|
||||
translation_key=CH3_HUMIDITY,
|
||||
value_fn=lambda data: cast(int, data),
|
||||
),
|
||||
# WeatherSensorEntityDescription(
|
||||
# key=CH4_TEMP,
|
||||
# native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||
|
|
@ -256,4 +305,11 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
translation_key=CHILL_INDEX,
|
||||
value_fn=lambda data: cast("int", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=OUTSIDE_BATTERY,
|
||||
translation_key=OUTSIDE_BATTERY,
|
||||
icon="mdi:battery-unknown",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
value_fn=lambda data: battery_level_to_text(data),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -131,6 +131,14 @@
|
|||
"wnw": "WNW",
|
||||
"nw": "NW",
|
||||
"nnw": "NNW"
|
||||
},
|
||||
"outside_battery": {
|
||||
"name": "Outside battery level",
|
||||
"state": {
|
||||
"normal": "OK",
|
||||
"low": "Low",
|
||||
"unknown": "Unknown / drained out"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@
|
|||
"ch4_humidity": { "name": "Vlhkost sensoru 4" },
|
||||
"heat_index": { "name": "Tepelný index" },
|
||||
"chill_index": { "name": "Pocitová teplota" },
|
||||
"hourly_rain": { "name": "Hodinový úhrn srážek" },
|
||||
"weekly_rain": { "name": "Týdenní úhrn srážek" },
|
||||
"monthly_rain": { "name": "Měsíční úhrn srážek" },
|
||||
"yearly_rain": { "name": "Roční úhrn srážek" },
|
||||
"wind_azimut": {
|
||||
"name": "Azimut",
|
||||
"state": {
|
||||
|
|
@ -132,6 +136,14 @@
|
|||
"nw": "SZ",
|
||||
"nnw": "SSZ"
|
||||
}
|
||||
},
|
||||
"outside_battery": {
|
||||
"name": "Stav nabití venkovní baterie",
|
||||
"state": {
|
||||
"low": "Nízká",
|
||||
"normal": "Normální",
|
||||
"unknown": "Neznámá / zcela vybitá"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@
|
|||
},
|
||||
|
||||
"step": {
|
||||
|
||||
"init": {
|
||||
"title": "Configure SWS12500 Integration",
|
||||
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
||||
|
|
@ -83,8 +82,8 @@
|
|||
"trigger_action": "Trigger migration"
|
||||
},
|
||||
"data_description": {
|
||||
"sensor_to_migrate": "Select the correct sensor for statistics migration.\nThe sensor values will be preserved, they will not be recalculated, only the unit in the long-term statistics will be changed.",
|
||||
"trigger_action": "Trigger the sensor statistics migration after checking."
|
||||
"sensor_to_migrate": "Select the correct sensor for statistics migration.\nThe sensor values will be preserved, they will not be recalculated, only the unit in the long-term statistics will be changed.",
|
||||
"trigger_action": "Trigger the sensor statistics migration after checking."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,6 +112,10 @@
|
|||
"ch4_humidity": { "name": "Channel 4 humidity" },
|
||||
"heat_index": { "name": "Apparent temperature" },
|
||||
"chill_index": { "name": "Wind chill" },
|
||||
"hourly_rain": { "name": "Hourly precipitation" },
|
||||
"weekly_rain": { "name": "Weekly precipitation" },
|
||||
"monthly_rain": { "name": "Monthly precipitation" },
|
||||
"yearly_rain": { "name": "Yearly precipitation" },
|
||||
"wind_azimut": {
|
||||
"name": "Bearing",
|
||||
"state": {
|
||||
|
|
@ -133,6 +136,14 @@
|
|||
"nw": "NW",
|
||||
"nnw": "NNW"
|
||||
}
|
||||
},
|
||||
"outside_battery": {
|
||||
"name": "Outside battery level",
|
||||
"state": {
|
||||
"normal": "OK",
|
||||
"low": "Low",
|
||||
"unknown": "Unknown / drained out"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from homeassistant.helpers.translation import async_get_translations
|
|||
|
||||
from .const import (
|
||||
AZIMUT,
|
||||
BATTERY_LEVEL,
|
||||
DATABASE_PATH,
|
||||
DEV_DBG,
|
||||
OUTSIDE_HUMIDITY,
|
||||
|
|
@ -29,6 +30,7 @@ from .const import (
|
|||
SENSORS_TO_LOAD,
|
||||
WIND_SPEED,
|
||||
UnitOfDir,
|
||||
UnitOfBat,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
|
@ -181,6 +183,32 @@ def wind_dir_to_text(deg: float) -> UnitOfDir | None:
|
|||
return None
|
||||
|
||||
|
||||
def battery_level_to_text(battery: int) -> UnitOfBat:
|
||||
"""Return battery level in text representation.
|
||||
|
||||
Returns UnitOfBat
|
||||
"""
|
||||
|
||||
return {
|
||||
0: UnitOfBat.LOW,
|
||||
1: UnitOfBat.NORMAL,
|
||||
}.get(int(battery) if battery is not None else None, UnitOfBat.UNKNOWN)
|
||||
|
||||
|
||||
def battery_level_to_icon(battery: UnitOfBat) -> str:
|
||||
"""Return battery level in icon representation.
|
||||
|
||||
Returns str
|
||||
"""
|
||||
|
||||
icons = {
|
||||
UnitOfBat.LOW: "mdi:battery-low",
|
||||
UnitOfBat.NORMAL: "mdi:battery",
|
||||
}
|
||||
|
||||
return icons.get(battery, "mdi:battery-unknown")
|
||||
|
||||
|
||||
def fahrenheit_to_celsius(fahrenheit: float) -> float:
|
||||
"""Convert Fahrenheit to Celsius."""
|
||||
return (fahrenheit - 32) * 5.0 / 9.0
|
||||
|
|
@ -267,10 +295,12 @@ def long_term_units_in_statistics_meta():
|
|||
db = conn.cursor()
|
||||
|
||||
try:
|
||||
db.execute("""
|
||||
db.execute(
|
||||
"""
|
||||
SELECT statistic_id, unit_of_measurement from statistics_meta
|
||||
WHERE statistic_id LIKE 'sensor.weather_station_sws%'
|
||||
""")
|
||||
"""
|
||||
)
|
||||
rows = db.fetchall()
|
||||
sensor_units = {
|
||||
statistic_id: f"{statistic_id} ({unit})" for statistic_id, unit in rows
|
||||
|
|
@ -284,7 +314,46 @@ def long_term_units_in_statistics_meta():
|
|||
return sensor_units
|
||||
|
||||
|
||||
def migrate_data(sensor_id: str | None = None):
|
||||
async def migrate_data(hass: HomeAssistant, sensor_id: str | None = None) -> bool:
|
||||
"""Migrate data from mm/d to mm."""
|
||||
|
||||
_LOGGER.debug("Sensor %s is required for data migration", sensor_id)
|
||||
updated_rows = 0
|
||||
|
||||
if not Path(DATABASE_PATH).exists():
|
||||
_LOGGER.error("Database file not found: %s", DATABASE_PATH)
|
||||
return False
|
||||
|
||||
conn = sqlite3.connect(DATABASE_PATH)
|
||||
db = conn.cursor()
|
||||
|
||||
try:
|
||||
_LOGGER.info(sensor_id)
|
||||
db.execute(
|
||||
"""
|
||||
UPDATE statistics_meta
|
||||
SET unit_of_measurement = 'mm'
|
||||
WHERE statistic_id = ?
|
||||
AND unit_of_measurement = 'mm/d';
|
||||
""",
|
||||
(sensor_id,),
|
||||
)
|
||||
updated_rows = db.rowcount
|
||||
conn.commit()
|
||||
_LOGGER.info(
|
||||
"Data migration completed successfully. Updated rows: %s for %s",
|
||||
updated_rows,
|
||||
sensor_id,
|
||||
)
|
||||
|
||||
except sqlite3.Error as e:
|
||||
_LOGGER.error("Error during data migration: %s", e)
|
||||
finally:
|
||||
conn.close()
|
||||
return updated_rows
|
||||
|
||||
|
||||
def migrate_data_old(sensor_id: str | None = None):
|
||||
"""Migrate data from mm/d to mm."""
|
||||
updated_rows = 0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue