mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
Add extra sensors to Blebox (#90516)
This commit is contained in:
parent
56e5c34283
commit
e911b73b61
@ -7,10 +7,14 @@ from homeassistant.components.sensor import (
|
|||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
PERCENTAGE,
|
||||||
|
UnitOfEnergy,
|
||||||
|
UnitOfSpeed,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -40,6 +44,22 @@ SENSOR_TYPES = (
|
|||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
),
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="powerMeasurement",
|
||||||
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
|
state_class=SensorStateClass.TOTAL,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="humidity",
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="wind_speed",
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -75,3 +95,10 @@ class BleBoxSensorEntity(BleBoxEntity[blebox_uniapi.sensor.BaseSensor], SensorEn
|
|||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._feature.native_value
|
return self._feature.native_value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_reset(self):
|
||||||
|
"""Return the time when the sensor was last reset, if implemented."""
|
||||||
|
native_implementation = getattr(self._feature, "last_reset", None)
|
||||||
|
|
||||||
|
return native_implementation or super().last_reset
|
||||||
|
@ -37,14 +37,14 @@ def setup_product_mock(category, feature_mocks, path=None):
|
|||||||
return product_mock
|
return product_mock
|
||||||
|
|
||||||
|
|
||||||
def mock_only_feature(spec, **kwargs):
|
def mock_only_feature(spec, set_spec: bool = True, **kwargs):
|
||||||
"""Mock just the feature, without the product setup."""
|
"""Mock just the feature, without the product setup."""
|
||||||
return mock.create_autospec(spec, True, True, **kwargs)
|
return mock.create_autospec(spec, set_spec, True, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def mock_feature(category, spec, **kwargs):
|
def mock_feature(category, spec, set_spec: bool = True, **kwargs):
|
||||||
"""Mock a feature along with whole product setup."""
|
"""Mock a feature along with whole product setup."""
|
||||||
feature_mock = mock_only_feature(spec, **kwargs)
|
feature_mock = mock_only_feature(spec, set_spec, **kwargs)
|
||||||
feature_mock.async_update = AsyncMock()
|
feature_mock.async_update = AsyncMock()
|
||||||
product = setup_product_mock(category, [feature_mock])
|
product = setup_product_mock(category, [feature_mock])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user