| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| """Implementation of baby cry detection module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from ...feature import Feature | ||
| from ..smartcammodule import SmartCamModule | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Battery(SmartCamModule): | ||
| """Implementation of a battery module.""" | ||
|
|
||
| REQUIRED_COMPONENT = "battery" | ||
|
|
||
| def _initialize_features(self) -> None: | ||
| """Initialize features.""" | ||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| "battery_low", | ||
| "Battery low", | ||
| container=self, | ||
| attribute_getter="battery_low", | ||
| icon="mdi:alert", | ||
| type=Feature.Type.BinarySensor, | ||
| category=Feature.Category.Debug, | ||
| ) | ||
| ) | ||
|
|
||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| "battery_level", | ||
| "Battery level", | ||
| container=self, | ||
| attribute_getter="battery_percent", | ||
| icon="mdi:battery", | ||
| unit_getter=lambda: "%", | ||
| category=Feature.Category.Info, | ||
| type=Feature.Type.Sensor, | ||
| ) | ||
| ) | ||
|
|
||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| "battery_temperature", | ||
| "Battery temperature", | ||
| container=self, | ||
| attribute_getter="battery_temperature", | ||
| icon="mdi:battery", | ||
| unit_getter=lambda: "celsius", | ||
| category=Feature.Category.Debug, | ||
| type=Feature.Type.Sensor, | ||
| ) | ||
| ) | ||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| "battery_voltage", | ||
| "Battery voltage", | ||
| container=self, | ||
| attribute_getter="battery_voltage", | ||
| icon="mdi:battery", | ||
| unit_getter=lambda: "V", | ||
| category=Feature.Category.Debug, | ||
| type=Feature.Type.Sensor, | ||
| ) | ||
| ) | ||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| "battery_charging", | ||
| "Battery charging", | ||
| container=self, | ||
| attribute_getter="battery_charging", | ||
| icon="mdi:alert", | ||
| type=Feature.Type.BinarySensor, | ||
| category=Feature.Category.Debug, | ||
| ) | ||
| ) | ||
|
|
||
| def query(self) -> dict: | ||
| """Query to execute during the update cycle.""" | ||
| return {} | ||
|
|
||
| @property | ||
| def battery_percent(self) -> int: | ||
| """Return battery level.""" | ||
| return self._device.sys_info["battery_percent"] | ||
|
|
||
| @property | ||
| def battery_low(self) -> bool: | ||
| """Return True if battery is low.""" | ||
| return self._device.sys_info["low_battery"] | ||
|
|
||
| @property | ||
| def battery_temperature(self) -> bool: | ||
| """Return battery voltage in C.""" | ||
| return self._device.sys_info["battery_temperature"] | ||
|
|
||
| @property | ||
| def battery_voltage(self) -> bool: | ||
| """Return battery voltage in V.""" | ||
| return self._device.sys_info["battery_voltage"] / 1_000 | ||
|
|
||
| @property | ||
| def battery_charging(self) -> bool: | ||
| """Return True if battery is charging.""" | ||
| return self._device.sys_info["battery_voltage"] != "NO" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Tests for smartcam battery module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from kasa import Device | ||
| from kasa.smartcam.smartcammodule import SmartCamModule | ||
|
|
||
| from ...device_fixtures import parametrize | ||
|
|
||
| battery_smartcam = parametrize( | ||
| "has battery", | ||
| component_filter="battery", | ||
| protocol_filter={"SMARTCAM", "SMARTCAM.CHILD"}, | ||
| ) | ||
|
|
||
|
|
||
| @battery_smartcam | ||
| async def test_battery(dev: Device): | ||
| """Test device battery.""" | ||
| battery = dev.modules.get(SmartCamModule.SmartCamBattery) | ||
| assert battery | ||
|
|
||
| feat_ids = { | ||
| "battery_level", | ||
| "battery_low", | ||
| "battery_temperature", | ||
| "battery_voltage", | ||
| "battery_charging", | ||
| } | ||
| for feat_id in feat_ids: | ||
| feat = dev.features.get(feat_id) | ||
| assert feat | ||
| assert feat.value is not None |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWas this change intentional?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes, the previous mapping logic only mapped a fix set of keys but didn't leave the extra keys behind which we need to access other properties of sysinfo.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.