2024-02-22 22:09:38 +00:00
|
|
|
"""Implementation of battery module."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-02-22 22:09:38 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 22:09:38 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..smartdevice import SmartDevice
|
|
|
|
|
|
|
|
|
|
|
|
class BatterySensor(SmartModule):
|
|
|
|
"""Implementation of battery module."""
|
|
|
|
|
|
|
|
REQUIRED_COMPONENT = "battery_detect"
|
|
|
|
QUERY_GETTER_NAME = "get_battery_detect_info"
|
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
def __init__(self, device: SmartDevice, module: str):
|
2024-02-22 22:09:38 +00:00
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
"battery_level",
|
2024-02-22 22:09:38 +00:00
|
|
|
"Battery level",
|
|
|
|
container=self,
|
|
|
|
attribute_getter="battery",
|
|
|
|
icon="mdi:battery",
|
2024-05-07 09:13:35 +00:00
|
|
|
unit="%",
|
|
|
|
category=Feature.Category.Info,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
"battery_low",
|
2024-02-22 22:09:38 +00:00
|
|
|
"Battery low",
|
|
|
|
container=self,
|
|
|
|
attribute_getter="battery_low",
|
|
|
|
icon="mdi:alert",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.BinarySensor,
|
2024-05-07 09:13:35 +00:00
|
|
|
category=Feature.Category.Debug,
|
2024-02-22 22:09:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def battery(self):
|
|
|
|
"""Return battery level."""
|
|
|
|
return self._device.sys_info["battery_percentage"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def battery_low(self):
|
|
|
|
"""Return True if battery is low."""
|
|
|
|
return self._device.sys_info["at_low_battery"]
|