Add devices to Verisure integration (#47913)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Franck Nijhof 2021-03-15 23:59:41 +01:00 committed by GitHub
parent 9fd973d8e8
commit 5f627df6f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 163 additions and 21 deletions

View file

@ -1,7 +1,7 @@
"""Support for Verisure sensors."""
from __future__ import annotations
from typing import Callable, Iterable
from typing import Any, Callable, Iterable
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .const import CONF_GIID, DEVICE_TYPE_NAME, DOMAIN
from .coordinator import VerisureDataUpdateCoordinator
@ -64,6 +64,22 @@ class VerisureThermometer(CoordinatorEntity, Entity):
"""Return the unique ID for this entity."""
return f"{self.serial_number}_temperature"
@property
def device_info(self) -> dict[str, Any]:
"""Return device information about this entity."""
device_type = self.coordinator.data["climate"][self.serial_number].get(
"deviceType"
)
area = self.coordinator.data["climate"][self.serial_number]["deviceArea"]
return {
"name": area,
"suggested_area": area,
"manufacturer": "Verisure",
"model": DEVICE_TYPE_NAME.get(device_type, device_type),
"identifiers": {(DOMAIN, self.serial_number)},
"via_device": (DOMAIN, self.coordinator.entry.data[CONF_GIID]),
}
@property
def state(self) -> str | None:
"""Return the state of the entity."""
@ -107,6 +123,22 @@ class VerisureHygrometer(CoordinatorEntity, Entity):
"""Return the unique ID for this entity."""
return f"{self.serial_number}_humidity"
@property
def device_info(self) -> dict[str, Any]:
"""Return device information about this entity."""
device_type = self.coordinator.data["climate"][self.serial_number].get(
"deviceType"
)
area = self.coordinator.data["climate"][self.serial_number]["deviceArea"]
return {
"name": area,
"suggested_area": area,
"manufacturer": "Verisure",
"model": DEVICE_TYPE_NAME.get(device_type, device_type),
"identifiers": {(DOMAIN, self.serial_number)},
"via_device": (DOMAIN, self.coordinator.entry.data[CONF_GIID]),
}
@property
def state(self) -> str | None:
"""Return the state of the entity."""
@ -150,6 +182,19 @@ class VerisureMouseDetection(CoordinatorEntity, Entity):
"""Return the unique ID for this entity."""
return f"{self.serial_number}_mice"
@property
def device_info(self) -> dict[str, Any]:
"""Return device information about this entity."""
area = self.coordinator.data["mice"][self.serial_number]["area"]
return {
"name": area,
"suggested_area": area,
"manufacturer": "Verisure",
"model": "Mouse detector",
"identifiers": {(DOMAIN, self.serial_number)},
"via_device": (DOMAIN, self.coordinator.entry.data[CONF_GIID]),
}
@property
def state(self) -> str | None:
"""Return the state of the device."""