Compare commits
1 Commits
2b3788834c
...
e432ee7c3a
| Author | SHA1 | Date |
|---|---|---|
|
|
e432ee7c3a |
|
|
@ -20,7 +20,7 @@ from homeassistant.helpers.translation import async_get_translations
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
AZIMUT,
|
AZIMUT,
|
||||||
BATTERY_LEVEL,
|
BATLEVEL,
|
||||||
DATABASE_PATH,
|
DATABASE_PATH,
|
||||||
DEV_DBG,
|
DEV_DBG,
|
||||||
OUTSIDE_HUMIDITY,
|
OUTSIDE_HUMIDITY,
|
||||||
|
|
@ -30,7 +30,6 @@ from .const import (
|
||||||
SENSORS_TO_LOAD,
|
SENSORS_TO_LOAD,
|
||||||
WIND_SPEED,
|
WIND_SPEED,
|
||||||
UnitOfDir,
|
UnitOfDir,
|
||||||
UnitOfBat,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
@ -182,33 +181,19 @@ def wind_dir_to_text(deg: float) -> UnitOfDir | None:
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def battery_level_to_text(battery: int) -> str:
|
||||||
def battery_level_to_text(battery: int) -> UnitOfBat:
|
|
||||||
"""Return battery level in text representation.
|
"""Return battery level in text representation.
|
||||||
|
|
||||||
Returns UnitOfBat
|
Returns UnitOfBat or None
|
||||||
"""
|
"""
|
||||||
|
if battery is None:
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
return {
|
if battery is 0:
|
||||||
0: UnitOfBat.LOW,
|
return BATLEVEL[battery]
|
||||||
1: UnitOfBat.NORMAL,
|
elif battery is 1:
|
||||||
}.get(battery, UnitOfBat.UNKNOWN)
|
return BATLEVEL[battery]
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -295,12 +280,10 @@ 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
|
||||||
|
|
@ -316,8 +299,8 @@ def long_term_units_in_statistics_meta():
|
||||||
|
|
||||||
async def migrate_data(hass: HomeAssistant, sensor_id: str | None = None) -> bool:
|
async def migrate_data(hass: HomeAssistant, sensor_id: str | None = None) -> bool:
|
||||||
"""Migrate data from mm/d to mm."""
|
"""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
|
updated_rows = 0
|
||||||
|
|
||||||
if not Path(DATABASE_PATH).exists():
|
if not Path(DATABASE_PATH).exists():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue