Merge e11e068c0f into 99d25bfd56
commit
e832a82196
|
|
@ -23,8 +23,12 @@ WSLINK: Final = "wslink"
|
||||||
WINDY_API_KEY = "WINDY_API_KEY"
|
WINDY_API_KEY = "WINDY_API_KEY"
|
||||||
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
||||||
WINDY_LOGGER_ENABLED: Final = "windy_logger_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_NOT_INSERTED: Final = (
|
||||||
WINDY_INVALID_KEY: Final = "Windy API KEY is invalid. Send data to Windy is now disabled. Check your API KEY and try again."
|
"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_SUCCESS: Final = (
|
||||||
"Windy successfully sent data and data was successfully inserted by Windy API"
|
"Windy successfully sent data and data was successfully inserted by Windy API"
|
||||||
)
|
)
|
||||||
|
|
@ -63,6 +67,7 @@ OUTSIDE_TEMP: Final = "outside_temp"
|
||||||
DEW_POINT: Final = "dew_point"
|
DEW_POINT: Final = "dew_point"
|
||||||
OUTSIDE_HUMIDITY: Final = "outside_humidity"
|
OUTSIDE_HUMIDITY: Final = "outside_humidity"
|
||||||
OUTSIDE_CONNECTION: Final = "outside_connection"
|
OUTSIDE_CONNECTION: Final = "outside_connection"
|
||||||
|
OUTSIDE_BATTERY: Final = "outside_battery"
|
||||||
WIND_SPEED: Final = "wind_speed"
|
WIND_SPEED: Final = "wind_speed"
|
||||||
WIND_GUST: Final = "wind_gust"
|
WIND_GUST: Final = "wind_gust"
|
||||||
WIND_DIR: Final = "wind_dir"
|
WIND_DIR: Final = "wind_dir"
|
||||||
|
|
@ -137,6 +142,7 @@ REMAP_WSLINK_ITEMS: dict = {
|
||||||
"t1rainwy": WEEKLY_RAIN,
|
"t1rainwy": WEEKLY_RAIN,
|
||||||
"t1rainmth": MONTHLY_RAIN,
|
"t1rainmth": MONTHLY_RAIN,
|
||||||
"t1rainyr": YEARLY_RAIN,
|
"t1rainyr": YEARLY_RAIN,
|
||||||
|
"t1bat": OUTSIDE_BATTERY,
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Add more sensors
|
# TODO: Add more sensors
|
||||||
|
|
@ -153,6 +159,7 @@ DISABLED_BY_DEFAULT: Final = [
|
||||||
CH3_HUMIDITY,
|
CH3_HUMIDITY,
|
||||||
CH4_TEMP,
|
CH4_TEMP,
|
||||||
CH4_HUMIDITY,
|
CH4_HUMIDITY,
|
||||||
|
OUTSIDE_BATTERY,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -195,3 +202,18 @@ AZIMUT: list[UnitOfDir] = [
|
||||||
UnitOfDir.NNW,
|
UnitOfDir.NNW,
|
||||||
UnitOfDir.N,
|
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,
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -27,25 +27,26 @@ from .const import (
|
||||||
DAILY_RAIN,
|
DAILY_RAIN,
|
||||||
DEW_POINT,
|
DEW_POINT,
|
||||||
HEAT_INDEX,
|
HEAT_INDEX,
|
||||||
|
HOURLY_RAIN,
|
||||||
INDOOR_HUMIDITY,
|
INDOOR_HUMIDITY,
|
||||||
INDOOR_TEMP,
|
INDOOR_TEMP,
|
||||||
|
MONTHLY_RAIN,
|
||||||
|
OUTSIDE_BATTERY,
|
||||||
OUTSIDE_HUMIDITY,
|
OUTSIDE_HUMIDITY,
|
||||||
OUTSIDE_TEMP,
|
OUTSIDE_TEMP,
|
||||||
RAIN,
|
RAIN,
|
||||||
SOLAR_RADIATION,
|
SOLAR_RADIATION,
|
||||||
UV,
|
UV,
|
||||||
|
WEEKLY_RAIN,
|
||||||
WIND_AZIMUT,
|
WIND_AZIMUT,
|
||||||
WIND_DIR,
|
WIND_DIR,
|
||||||
WIND_GUST,
|
WIND_GUST,
|
||||||
WIND_SPEED,
|
WIND_SPEED,
|
||||||
UnitOfDir,
|
|
||||||
MONTHLY_RAIN,
|
|
||||||
YEARLY_RAIN,
|
YEARLY_RAIN,
|
||||||
HOURLY_RAIN,
|
UnitOfDir,
|
||||||
WEEKLY_RAIN,
|
|
||||||
)
|
)
|
||||||
from .sensors_common import WeatherSensorEntityDescription
|
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, ...] = (
|
SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||||
WeatherSensorEntityDescription(
|
WeatherSensorEntityDescription(
|
||||||
|
|
@ -303,4 +304,11 @@ SENSOR_TYPES_WSLINK: tuple[WeatherSensorEntityDescription, ...] = (
|
||||||
translation_key=CHILL_INDEX,
|
translation_key=CHILL_INDEX,
|
||||||
value_fn=lambda data: cast("int", data),
|
value_fn=lambda data: cast("int", data),
|
||||||
),
|
),
|
||||||
|
WeatherSensorEntityDescription(
|
||||||
|
key=OUTSIDE_BATTERY,
|
||||||
|
translation_key=OUTSIDE_BATTERY,
|
||||||
|
icon=lambda data: battery_level_to_icon(battery_level_to_text(int(data))),
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
value_fn=lambda data: battery_level_to_text(int(data)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,14 @@
|
||||||
"wnw": "WNW",
|
"wnw": "WNW",
|
||||||
"nw": "NW",
|
"nw": "NW",
|
||||||
"nnw": "NNW"
|
"nnw": "NNW"
|
||||||
|
},
|
||||||
|
"outside_battery": {
|
||||||
|
"name": "Outside battery level",
|
||||||
|
"state": {
|
||||||
|
"normal": "OK",
|
||||||
|
"low": "Low",
|
||||||
|
"unknown": "Unknown / drained out"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,14 @@
|
||||||
"nw": "SZ",
|
"nw": "SZ",
|
||||||
"nnw": "SSZ"
|
"nnw": "SSZ"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"outside_battery": {
|
||||||
|
"name": "Stav nabití venkovní baterie",
|
||||||
|
"state": {
|
||||||
|
"low": "Nízká",
|
||||||
|
"normal": "Normální",
|
||||||
|
"unknown": "Neznámá / zcela vybitá"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,14 @@
|
||||||
"nw": "NW",
|
"nw": "NW",
|
||||||
"nnw": "NNW"
|
"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 (
|
from .const import (
|
||||||
AZIMUT,
|
AZIMUT,
|
||||||
|
BATTERY_LEVEL,
|
||||||
DATABASE_PATH,
|
DATABASE_PATH,
|
||||||
DEV_DBG,
|
DEV_DBG,
|
||||||
OUTSIDE_HUMIDITY,
|
OUTSIDE_HUMIDITY,
|
||||||
|
|
@ -29,6 +30,7 @@ from .const import (
|
||||||
SENSORS_TO_LOAD,
|
SENSORS_TO_LOAD,
|
||||||
WIND_SPEED,
|
WIND_SPEED,
|
||||||
UnitOfDir,
|
UnitOfDir,
|
||||||
|
UnitOfBat,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
@ -181,6 +183,32 @@ def wind_dir_to_text(deg: float) -> UnitOfDir | None:
|
||||||
return 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:
|
def fahrenheit_to_celsius(fahrenheit: float) -> float:
|
||||||
"""Convert Fahrenheit to Celsius."""
|
"""Convert Fahrenheit to Celsius."""
|
||||||
return (fahrenheit - 32) * 5.0 / 9.0
|
return (fahrenheit - 32) * 5.0 / 9.0
|
||||||
|
|
@ -267,10 +295,12 @@ def long_term_units_in_statistics_meta():
|
||||||
db = conn.cursor()
|
db = conn.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.execute("""
|
db.execute(
|
||||||
|
"""
|
||||||
SELECT statistic_id, unit_of_measurement from statistics_meta
|
SELECT statistic_id, unit_of_measurement from statistics_meta
|
||||||
WHERE statistic_id LIKE 'sensor.weather_station_sws%'
|
WHERE statistic_id LIKE 'sensor.weather_station_sws%'
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
rows = db.fetchall()
|
rows = db.fetchall()
|
||||||
sensor_units = {
|
sensor_units = {
|
||||||
statistic_id: f"{statistic_id} ({unit})" for statistic_id, unit in rows
|
statistic_id: f"{statistic_id} ({unit})" for statistic_id, unit in rows
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue