Improves battery level representation
Refactors battery level representation by using enum instead of string. Improves battery level display by adding an icon representation. Changes const BATLEVEL to BATTERY_LEVEL.pull/72/head
parent
a68a4c929a
commit
3dbf8b8a7a
|
|
@ -20,7 +20,7 @@ from homeassistant.helpers.translation import async_get_translations
|
|||
|
||||
from .const import (
|
||||
AZIMUT,
|
||||
BATLEVEL,
|
||||
BATTERY_LEVEL,
|
||||
DATABASE_PATH,
|
||||
DEV_DBG,
|
||||
OUTSIDE_HUMIDITY,
|
||||
|
|
@ -30,6 +30,7 @@ from .const import (
|
|||
SENSORS_TO_LOAD,
|
||||
WIND_SPEED,
|
||||
UnitOfDir,
|
||||
UnitOfBat,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
|
@ -181,18 +182,32 @@ def wind_dir_to_text(deg: float) -> UnitOfDir | 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.
|
||||
|
||||
Returns UnitOfBat or None
|
||||
Returns UnitOfBat
|
||||
"""
|
||||
if battery is None:
|
||||
return "unknown"
|
||||
|
||||
if battery is 0:
|
||||
return BATLEVEL[battery]
|
||||
elif battery is 1:
|
||||
return BATLEVEL[battery]
|
||||
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."""
|
||||
|
|
@ -280,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
|
||||
|
|
|
|||
Loading…
Reference in New Issue