Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions homeassistant/components/devolo_home_control/devolo_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def _sync(self, message):
self.schedule_update_ha_state()

def _generic_message(self, message):
"""Handle unexpected messages."""
if message[0].startswith("hdm"):
"""Handle generic messages."""
if len(message) == 3 and message[2] == "battery_level":
self._value = message[1]
elif len(message) == 3 and message[2] == "status":
# Maybe the API wants to tell us, that the device went on- or offline.
self._available = self._device_instance.is_online()
else:
Expand Down
29 changes: 29 additions & 0 deletions homeassistant/components/devolo_home_control/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import logging

from homeassistant.components.sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE
from homeassistant.helpers.typing import HomeAssistantType

from .const import DOMAIN
Expand All @@ -16,6 +18,7 @@
_LOGGER = logging.getLogger(__name__)

DEVICE_CLASS_MAPPING = {
"battery": DEVICE_CLASS_BATTERY,
"temperature": DEVICE_CLASS_TEMPERATURE,
"light": DEVICE_CLASS_ILLUMINANCE,
"humidity": DEVICE_CLASS_HUMIDITY,
Expand Down Expand Up @@ -51,6 +54,14 @@ async def async_setup_entry(
consumption=consumption_type,
)
)
if hasattr(device, "battery_level"):
entities.append(
DevoloBatteryEntity(
homecontrol=hass.data[DOMAIN]["homecontrol"],
device_instance=device,
element_uid=f"devolo.BatterySensor:{device.uid}",
)
)
async_add_entities(entities, False)


Expand Down Expand Up @@ -104,6 +115,24 @@ def __init__(
self._name += f" {self._multi_level_sensor_property.sensor_type}"


class DevoloBatteryEntity(DevoloMultiLevelDeviceEntity):
"""Representation of a battery entity within devolo Home Control."""

def __init__(self, homecontrol, device_instance, element_uid):
"""Initialize a battery sensor."""

super().__init__(
homecontrol=homecontrol,
device_instance=device_instance,
element_uid=element_uid,
)

self._device_class = DEVICE_CLASS_MAPPING.get("battery")

self._value = device_instance.battery_level
self._unit = PERCENTAGE


class DevoloConsumptionEntity(DevoloMultiLevelDeviceEntity):
"""Representation of a consumption entity within devolo Home Control."""

Expand Down