Merge 68da7aad98 into 99d25bfd56
commit
2b3788834c
|
|
@ -63,6 +63,7 @@ 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"
|
||||
|
|
@ -137,6 +138,7 @@ REMAP_WSLINK_ITEMS: dict = {
|
|||
"t1rainwy": WEEKLY_RAIN,
|
||||
"t1rainmth": MONTHLY_RAIN,
|
||||
"t1rainyr": YEARLY_RAIN,
|
||||
"t1bat": OUTSIDE_BATTERY,
|
||||
}
|
||||
|
||||
# TODO: Add more sensors
|
||||
|
|
@ -176,7 +178,6 @@ class UnitOfDir(StrEnum):
|
|||
NNW = "nnw"
|
||||
N = "n"
|
||||
|
||||
|
||||
AZIMUT: list[UnitOfDir] = [
|
||||
UnitOfDir.NNE,
|
||||
UnitOfDir.NE,
|
||||
|
|
@ -195,3 +196,16 @@ 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,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from .const import (
|
|||
HEAT_INDEX,
|
||||
INDOOR_HUMIDITY,
|
||||
INDOOR_TEMP,
|
||||
OUTSIDE_BATTERY,
|
||||
OUTSIDE_HUMIDITY,
|
||||
OUTSIDE_TEMP,
|
||||
RAIN,
|
||||
|
|
@ -45,7 +46,7 @@ from .const import (
|
|||
WEEKLY_RAIN,
|
||||
)
|
||||
from .sensors_common import WeatherSensorEntityDescription
|
||||
from .utils import wind_dir_to_text
|
||||
from .utils import battery_level_to_text, wind_dir_to_text
|
||||
|
||||
SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||
WeatherSensorEntityDescription(
|
||||
|
|
@ -303,4 +304,12 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
|||
translation_key=CHILL_INDEX,
|
||||
value_fn=lambda data: cast("int", data),
|
||||
),
|
||||
WeatherSensorEntityDescription(
|
||||
key=OUTSIDE_BATTERY,
|
||||
name="Outside Battery",
|
||||
icon="mdi:battery",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
value_fn=lambda data: battery_level_to_text(int(data)) if data is not None and str(data).isdigit() else "unknown",
|
||||
translation_key=OUTSIDE_BATTERY,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"outside_battery": { "name": "Outside battery level" },
|
||||
"notify": {
|
||||
"added": {
|
||||
"title": "New sensors for SWS 12500 found.",
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"outside_battery": { "name": "Vnější úroveň nabití baterie" },
|
||||
"notify": {
|
||||
"added": {
|
||||
"title": "Nalezeny nové senzory pro SWS 12500.",
|
||||
|
|
|
|||
|
|
@ -136,7 +136,8 @@
|
|||
"nw": "NW",
|
||||
"nnw": "NNW"
|
||||
}
|
||||
}
|
||||
},
|
||||
"outside_battery": { "name": "Outside battery level" }
|
||||
}
|
||||
},
|
||||
"notify": {
|
||||
|
|
|
|||
|
|
@ -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(battery, UnitOfBat.UNKNOWN)
|
||||
|
||||
|
||||
def battery_level_to_icon(battery: UnitOfBat) -> str:
|
||||
"""Return battery level in icon representation.
|
||||
|
||||
Returns str
|
||||
"""
|
||||
|
||||
icons = {
|
||||
UnitOfBat.LOW: "mdi:battery-alert",
|
||||
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
|
||||
|
|
@ -286,8 +316,8 @@ def long_term_units_in_statistics_meta():
|
|||
|
||||
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)
|
||||
|
||||
_LOGGER.debug("Sensor %s is required for data migration", sensor_id)
|
||||
updated_rows = 0
|
||||
|
||||
if not Path(DATABASE_PATH).exists():
|
||||
|
|
|
|||
Loading…
Reference in New Issue