From ec13c08bba57e065497937ac23e1beedae09f3c5 Mon Sep 17 00:00:00 2001 From: Andrey Khrolenok Date: Fri, 17 May 2024 14:54:07 +0300 Subject: [PATCH] Update README and add precipitation sensor --- README.md | 154 +++++++++++++++----------- custom_components/gismeteo/const.py | 28 ++++- custom_components/gismeteo/sensor.py | 2 - custom_components/gismeteo/weather.py | 2 + tests/test_sensor.py | 2 +- 5 files changed, 118 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 56c4aa5..3c82c1a 100644 --- a/README.md +++ b/README.md @@ -116,69 +116,99 @@ I put a lot of work into making this repo and component available and updated to > > How many days ahead to make forecast sensors.\ > > **Note:** If you only need a forecast sensors for today, specify `0`. +When `sensors` option are enabled, it creates 21 sensors. Each shows one aspect of current weather. Only few basic sensors are enabled by default. But you can enable any sensor through device settings. -> > > **condition**\ -> > > A human-readable text summary. -> > > -> > > **temperature**\ -> > > The current temperature of air. -> > > -> > > **temperature_feels_like**\ -> > > The current air temperature feels like. -> > > -> > > **humidity**\ -> > > The relative humidity of air. -> > > -> > > **pressure**\ -> > > The sea-level air pressure in millibars.\ -> > > At the same time, a second sensor is created, indicating the same pressure in mmHg. -> > > -> > > **wind_speed**\ -> > > The wind speed. -> > > -> > > **wind_bearing**\ -> > > The wind bearing. -> > > -> > > **clouds**\ -> > > Description about cloud coverage. -> > > -> > > **rain**\ -> > > The rain volume. -> > > -> > > **snow**\ -> > > The snow volume. -> > > -> > > **storm**\ -> > > The storm prediction. -> > > -> > > **geomagnetic**\ -> > > The geomagnetic field value:\ -> > > 1 = No noticeable geomagnetic disturbance\ -> > > 2 = Small geomagnetic disturbances\ -> > > 3 = Weak geomagnetic storm\ -> > > 4 = Small geomagnetic storm\ -> > > 5 = Moderate geomagnetic storm\ -> > > 6 = Severe geomagnetic storm\ -> > > 7 = Hard geomagnetic storm\ -> > > 8 = Extreme geomagnetic storm -> > > -> > > **water_temperature**\ -> > > The current temperature of water. -> > > -> > > **allergy_birch**\ -> > > Birch pollen concentration:\ -> > > 1–10 = Low\ -> > > 11–50 = Moderate\ -> > > 51–500 = High\ -> > > 501+ = Very high -> > > -> > > **uv_index**\ -> > > The ultraviolet index:\ -> > > 0–2 = Low\ -> > > 3–5 = Moderate\ -> > > 6–7 = High\ -> > > 8–10 = Very high\ -> > > 11+ = Extreme +When you add `forecast_days` option, integration creates additional 21 sensors for each day. Each shows one aspect of forecast weather for that day. As usual, only few basic sensors are enabled by default. + +List of sensors that will be created: +> **condition**\ +> A human-readable text summary. +> +> **temperature**\ +> The current temperature of air. +> +> **apparent_temperature**\ +> The current apparent air temperature. +> +> **humidity**\ +> The relative humidity of air. +> +> **pressure**\ +> The sea-level air pressure in millibars.\ +> At the same time, a second sensor is created, indicating the same pressure in mmHg. +> +> **wind_speed**\ +> The wind speed. +> +> **wind_gusts_speed**\ +> The wind gusts speed. +> +> **wind_bearing**\ +> The wind bearing as an angle. +> +> **wind_bearing_2**\ +> The wind bearing as text. +> +> **cloud_coverage**\ +> Cloud coverage as a percentage. +> +> **precipitation**\ +> The precipitation amount volume. +> +> **rain_amount**\ +> The rain amount volume. +> +> **snow_amount**\ +> The snow amount volume. +> +> **storm**\ +> The storm prediction. +> +> **geomagnetic_field**\ +> The geomagnetic field value:\ +> 1 = No noticeable geomagnetic disturbance\ +> 2 = Small geomagnetic disturbances\ +> 3 = Weak geomagnetic storm\ +> 4 = Small geomagnetic storm\ +> 5 = Moderate geomagnetic storm\ +> 6 = Severe geomagnetic storm\ +> 7 = Hard geomagnetic storm\ +> 8 = Extreme geomagnetic storm +> +> **water_temperature**\ +> The temperature of water. +> +> **uv_index**\ +> The ultraviolet index:\ +> 0–2 = Low\ +> 3–5 = Moderate\ +> 6–7 = High\ +> 8–10 = Very high\ +> 11+ = Extreme +> +> **birch_pollen**\ +> Birch pollen concentration index:\ +> 1–10 = Low\ +> 11–50 = Moderate\ +> 51–500 = High\ +> 501+ = Very high +> +> **grass_pollen**\ +> Cereal grasses pollen concentration index:\ +> 1–10 = Low\ +> 11–50 = Moderate\ +> 51–500 = High\ +> 501+ = Very high +> +> **ragweed_pollen**\ +> Ragweed pollen concentration index:\ +> 1–10 = Low\ +> 11–50 = Moderate\ +> 51–500 = High\ +> 501+ = Very high +> +> **road_condition**\ +> Road surface condition as text. ## Track updates diff --git a/custom_components/gismeteo/const.py b/custom_components/gismeteo/const.py index 5130f16..2dd2f62 100644 --- a/custom_components/gismeteo/const.py +++ b/custom_components/gismeteo/const.py @@ -26,7 +26,7 @@ DEGREE, PERCENTAGE, Platform, - UnitOfLength, + UnitOfPrecipitationDepth, UnitOfPressure, UnitOfSpeed, UnitOfTemperature, @@ -164,6 +164,13 @@ device_class=SensorDeviceClass.PRESSURE, native_unit_of_measurement=UnitOfPressure.HPA, ), + SensorEntityDescription( + key=ATTR_FORECAST_PRECIPITATION_AMOUNT, + translation_key="precipitation", + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, + entity_registry_enabled_default=False, + ), SensorEntityDescription( key=ATTR_FORECAST_WIND_SPEED, translation_key="wind_speed", @@ -202,14 +209,16 @@ key=ATTR_FORECAST_RAIN_AMOUNT, translation_key="rain_amount", icon="mdi:weather-rainy", - native_unit_of_measurement=UnitOfLength.MILLIMETERS, + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, entity_registry_enabled_default=False, ), SensorEntityDescription( key=ATTR_FORECAST_SNOW_AMOUNT, translation_key="snow_amount", icon="mdi:weather-snowy", - native_unit_of_measurement=UnitOfLength.MILLIMETERS, + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, entity_registry_enabled_default=False, ), SensorEntityDescription( @@ -289,6 +298,13 @@ device_class=SensorDeviceClass.PRESSURE, native_unit_of_measurement=UnitOfPressure.HPA, ), + SensorEntityDescription( + key=ATTR_FORECAST_PRECIPITATION_AMOUNT, + translation_key="precipitation_forecast", + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, + entity_registry_enabled_default=False, + ), SensorEntityDescription( key=ATTR_FORECAST_WIND_SPEED, translation_key="wind_speed_forecast", @@ -328,14 +344,16 @@ key=ATTR_FORECAST_RAIN_AMOUNT, translation_key="rain_amount_forecast", icon="mdi:weather-rainy", - native_unit_of_measurement=UnitOfLength.MILLIMETERS, + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, entity_registry_enabled_default=False, ), SensorEntityDescription( key=ATTR_FORECAST_SNOW_AMOUNT, translation_key="snow_amount_forecast", icon="mdi:weather-snowy", - native_unit_of_measurement=UnitOfLength.MILLIMETERS, + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, entity_registry_enabled_default=False, ), SensorEntityDescription( diff --git a/custom_components/gismeteo/sensor.py b/custom_components/gismeteo/sensor.py index 5e0a46d..ceea7b0 100644 --- a/custom_components/gismeteo/sensor.py +++ b/custom_components/gismeteo/sensor.py @@ -172,8 +172,6 @@ def __init__( super().__init__(coordinator, location_name) self.entity_description = description - # if day: - # self.entity_description.translation_key += "-day" self._attr_unique_id = ( f"{coordinator.unique_id}-{description.key}" diff --git a/custom_components/gismeteo/weather.py b/custom_components/gismeteo/weather.py index 2197b8a..c27b25b 100644 --- a/custom_components/gismeteo/weather.py +++ b/custom_components/gismeteo/weather.py @@ -18,6 +18,7 @@ from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( CONF_NAME, + UnitOfPrecipitationDepth, UnitOfPressure, UnitOfSpeed, UnitOfTemperature, @@ -72,6 +73,7 @@ class GismeteoWeather(GismeteoEntity, CoordinatorWeatherEntity): _attr_attribution = ATTRIBUTION _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_pressure_unit = UnitOfPressure.MMHG + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND _attr_supported_features = ( WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY diff --git a/tests/test_sensor.py b/tests/test_sensor.py index c244f66..d5040f9 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -52,7 +52,7 @@ async def test__fix_types(caplog): async def test__gen_entities(mock_coordinator): """Test _gen_entities function.""" res = _gen_entities("Test location", mock_coordinator, {}, False) - assert len(res) == 20 + assert len(res) == 21 res = _gen_entities( "Test location",