Skip to content

Commit

Permalink
Add state class measurement to sensors (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed May 18, 2024
1 parent b48e69a commit 0be8617
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion custom_components/gismeteo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ def cloud_coverage(self, src=None) -> float | None:
"""Return the cloud coverage amount in percents."""
src = src or self._current
cloudiness = src.get(ATTR_FORECAST_CLOUD_COVERAGE)
return int(cloudiness * 100 / 3) if cloudiness is not None else None
return (
50
if cloudiness == 101
else int(cloudiness * 100 / 3) if cloudiness is not None else None
)

def rain_amount(self, src=None) -> float | None:
"""Return the rain amount in mm."""
Expand Down
23 changes: 22 additions & 1 deletion custom_components/gismeteo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from enum import StrEnum
from typing import Final

from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.components.weather import (
ATTR_FORECAST_APPARENT_TEMP,
ATTR_FORECAST_CLOUD_COVERAGE,
Expand Down Expand Up @@ -152,44 +156,51 @@ class ForecastMode(StrEnum):
translation_key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_FORECAST_APPARENT_TEMP,
translation_key="apparent_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_FORECAST_HUMIDITY,
translation_key="humidity",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_FORECAST_PRESSURE,
translation_key="pressure",
device_class=SensorDeviceClass.PRESSURE,
native_unit_of_measurement=UnitOfPressure.MMHG,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_FORECAST_PRECIPITATION_AMOUNT,
translation_key="precipitation",
device_class=SensorDeviceClass.PRECIPITATION,
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_WIND_SPEED,
translation_key="wind_speed",
icon="mdi:weather-windy",
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_WIND_BEARING,
translation_key="wind_bearing",
icon="mdi:weather-windy",
native_unit_of_measurement=DEGREE,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
Expand All @@ -203,6 +214,7 @@ class ForecastMode(StrEnum):
translation_key="cloud_coverage",
icon="mdi:weather-partly-cloudy",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
Expand All @@ -211,6 +223,7 @@ class ForecastMode(StrEnum):
icon="mdi:weather-rainy",
device_class=SensorDeviceClass.PRECIPITATION,
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
Expand All @@ -219,45 +232,53 @@ class ForecastMode(StrEnum):
icon="mdi:weather-snowy",
device_class=SensorDeviceClass.PRECIPITATION,
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_IS_STORM,
translation_key="is_storm",
icon="mdi:weather-lightning",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_GEOMAGNETIC_FIELD,
translation_key="geomagnetic_field",
icon="mdi:magnet-on",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_WATER_TEMPERATURE,
translation_key="water_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_UV_INDEX,
translation_key="uv_index",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_POLLEN_BIRCH,
translation_key="pollen_birch",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_POLLEN_GRASS,
translation_key="pollen_grass",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_FORECAST_POLLEN_RAGWEED,
translation_key="pollen_ragweed",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
Expand Down

0 comments on commit 0be8617

Please sign in to comment.