Gogogate2 add statistics (#58178)

Co-authored-by: J. Nick Koston <nick@koston.org>
pull/58227/head
thomas-svrts 2021-10-22 14:24:43 +02:00 committed by GitHub
parent 164f09c1f0
commit f25d3cf9b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,7 @@ from itertools import chain
from ismartgate.common import AbstractDoor, get_configured_doors
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
@ -77,6 +77,11 @@ class DoorSensorBattery(GoGoGate2Entity, SensorEntity):
door = self._get_door()
return door.voltage # This is a percentage, not an absolute voltage
@property
def state_class(self) -> str:
"""Return the Measurement State Class."""
return STATE_CLASS_MEASUREMENT
@property
def extra_state_attributes(self):
"""Return the state attributes."""
@ -104,6 +109,11 @@ class DoorSensorTemperature(GoGoGate2Entity, SensorEntity):
"""Return the name of the door."""
return f"{self._get_door().name} temperature"
@property
def state_class(self) -> str:
"""Return the Measurement State Class."""
return STATE_CLASS_MEASUREMENT
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""

View File

@ -171,6 +171,7 @@ async def test_sensor_update(gogogate2api_mock, hass: HomeAssistant) -> None:
"door_id": 1,
"friendly_name": "Door1 battery",
"sensor_id": "ABCD",
"state_class": "measurement",
}
temp_attributes = {
"device_class": "temperature",
@ -178,6 +179,7 @@ async def test_sensor_update(gogogate2api_mock, hass: HomeAssistant) -> None:
"friendly_name": "Door1 temperature",
"sensor_id": "ABCD",
"unit_of_measurement": "°C",
"state_class": "measurement",
}
api = MagicMock(GogoGate2Api)
@ -245,6 +247,7 @@ async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
"door_id": 1,
"friendly_name": "Door1 battery",
"sensor_id": "ABCD",
"state_class": "measurement",
}
temp_attributes = {
"device_class": "temperature",
@ -252,6 +255,7 @@ async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
"friendly_name": "Door1 temperature",
"sensor_id": "ABCD",
"unit_of_measurement": "°C",
"state_class": "measurement",
}
sensor_response = _mocked_ismartgate_sensor_response(35, -4.0)