Compare commits
6 Commits
4055e79fba
...
b71ffdd4eb
| Author | SHA1 | Date |
|---|---|---|
|
|
b71ffdd4eb | |
|
|
fdcd28f96a | |
|
|
093a7915f0 | |
|
|
ea0a5e34e3 | |
|
|
fdd4cacddf | |
|
|
601d1f3984 |
|
|
@ -68,6 +68,10 @@ WIND_GUST: Final = "wind_gust"
|
||||||
WIND_DIR: Final = "wind_dir"
|
WIND_DIR: Final = "wind_dir"
|
||||||
WIND_AZIMUT: Final = "wind_azimut"
|
WIND_AZIMUT: Final = "wind_azimut"
|
||||||
RAIN: Final = "rain"
|
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"
|
DAILY_RAIN: Final = "daily_rain"
|
||||||
SOLAR_RADIATION: Final = "solar_radiation"
|
SOLAR_RADIATION: Final = "solar_radiation"
|
||||||
INDOOR_TEMP: Final = "indoor_temp"
|
INDOOR_TEMP: Final = "indoor_temp"
|
||||||
|
|
@ -129,15 +133,15 @@ REMAP_WSLINK_ITEMS: dict = {
|
||||||
"t234c2cn": CH3_CONNECTION,
|
"t234c2cn": CH3_CONNECTION,
|
||||||
"t1chill": CHILL_INDEX,
|
"t1chill": CHILL_INDEX,
|
||||||
"t1heat": HEAT_INDEX,
|
"t1heat": HEAT_INDEX,
|
||||||
|
"t1rainhr": HOURLY_RAIN,
|
||||||
|
"t1rainwy": WEEKLY_RAIN,
|
||||||
|
"t1rainmth": MONTHLY_RAIN,
|
||||||
|
"t1rainyr": YEARLY_RAIN,
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Add more sensors
|
# TODO: Add more sensors
|
||||||
#
|
#
|
||||||
# 'inbat' indoor battery level (1 normal, 0 low)
|
# '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)
|
# 't1bat': outdoor battery level (1 normal, 0 low)
|
||||||
# 't234c1bat': CH2 battery level (1 normal, 0 low) CH2 in integration is CH1 in WSLink
|
# 't234c1bat': CH2 battery level (1 normal, 0 low) CH2 in integration is CH1 in WSLink
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@
|
||||||
"issue_tracker": "https://github.com/schizza/SWS-12500-custom-component/issues",
|
"issue_tracker": "https://github.com/schizza/SWS-12500-custom-component/issues",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"ssdp": [],
|
"ssdp": [],
|
||||||
"version": "1.5.3",
|
"version": "1.6.2",
|
||||||
"zeroconf": []
|
"zeroconf": []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@ from .const import (
|
||||||
WIND_GUST,
|
WIND_GUST,
|
||||||
WIND_SPEED,
|
WIND_SPEED,
|
||||||
UnitOfDir,
|
UnitOfDir,
|
||||||
|
MONTHLY_RAIN,
|
||||||
|
YEARLY_RAIN,
|
||||||
|
HOURLY_RAIN,
|
||||||
|
WEEKLY_RAIN,
|
||||||
)
|
)
|
||||||
from .sensors_common import WeatherSensorEntityDescription
|
from .sensors_common import WeatherSensorEntityDescription
|
||||||
from .utils import wind_dir_to_text
|
from .utils import wind_dir_to_text
|
||||||
|
|
@ -139,10 +143,10 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||||
),
|
),
|
||||||
WeatherSensorEntityDescription(
|
WeatherSensorEntityDescription(
|
||||||
key=RAIN,
|
key=RAIN,
|
||||||
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
device_class=SensorDeviceClass.PRECIPITATION,
|
device_class=SensorDeviceClass.PRECIPITATION,
|
||||||
state_class=SensorStateClass.TOTAL,
|
state_class=SensorStateClass.TOTAL,
|
||||||
suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
suggested_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
suggested_display_precision=2,
|
suggested_display_precision=2,
|
||||||
icon="mdi:weather-pouring",
|
icon="mdi:weather-pouring",
|
||||||
translation_key=RAIN,
|
translation_key=RAIN,
|
||||||
|
|
@ -159,6 +163,50 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||||
translation_key=DAILY_RAIN,
|
translation_key=DAILY_RAIN,
|
||||||
value_fn=lambda data: cast("float", data),
|
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=DAILY_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=DAILY_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=DAILY_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=DAILY_RAIN,
|
||||||
|
value_fn=lambda data: cast("float", data),
|
||||||
|
),
|
||||||
WeatherSensorEntityDescription(
|
WeatherSensorEntityDescription(
|
||||||
key=SOLAR_RADIATION,
|
key=SOLAR_RADIATION,
|
||||||
native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
|
native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,10 @@
|
||||||
"ch4_humidity": { "name": "Vlhkost sensoru 4" },
|
"ch4_humidity": { "name": "Vlhkost sensoru 4" },
|
||||||
"heat_index": { "name": "Tepelný index" },
|
"heat_index": { "name": "Tepelný index" },
|
||||||
"chill_index": { "name": "Pocitová teplota" },
|
"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": {
|
"wind_azimut": {
|
||||||
"name": "Azimut",
|
"name": "Azimut",
|
||||||
"state": {
|
"state": {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"step": {
|
"step": {
|
||||||
|
|
||||||
"init": {
|
"init": {
|
||||||
"title": "Configure SWS12500 Integration",
|
"title": "Configure SWS12500 Integration",
|
||||||
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
||||||
|
|
@ -113,6 +112,10 @@
|
||||||
"ch4_humidity": { "name": "Channel 4 humidity" },
|
"ch4_humidity": { "name": "Channel 4 humidity" },
|
||||||
"heat_index": { "name": "Apparent temperature" },
|
"heat_index": { "name": "Apparent temperature" },
|
||||||
"chill_index": { "name": "Wind chill" },
|
"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": {
|
"wind_azimut": {
|
||||||
"name": "Bearing",
|
"name": "Bearing",
|
||||||
"state": {
|
"state": {
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,46 @@ def long_term_units_in_statistics_meta():
|
||||||
return sensor_units
|
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."""
|
"""Migrate data from mm/d to mm."""
|
||||||
updated_rows = 0
|
updated_rows = 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue