From 1d9dd2a1eb64918d6472feb417f284c9c8f5f3df Mon Sep 17 00:00:00 2001 From: Kev Date: Sun, 16 Jun 2024 15:55:10 -0400 Subject: [PATCH] Revert commits 644ca23 and e1bdd48 --- custom_components/pirateweather/manifest.json | 2 +- custom_components/pirateweather/sensor.py | 51 ++++++++----------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/custom_components/pirateweather/manifest.json b/custom_components/pirateweather/manifest.json index 4d1b90f..cac6dad 100644 --- a/custom_components/pirateweather/manifest.json +++ b/custom_components/pirateweather/manifest.json @@ -12,5 +12,5 @@ "requirements": [ "python-forecastio==1.4.0" ], - "version": "1.5.2.1" + "version": "1.5.2" } diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 504eb15..5cbf4ae 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -1,12 +1,14 @@ """Support for Pirate Weather (Dark Sky Compatable) weather service.""" import logging + from dataclasses import dataclass, field -from typing import Literal, NamedTuple +import voluptuous as vol import homeassistant.helpers.config_validation as cv import homeassistant.helpers.template as template_helper -import voluptuous as vol + + from homeassistant.components.sensor import ( PLATFORM_SCHEMA, SensorDeviceClass, @@ -14,7 +16,14 @@ SensorEntityDescription, SensorStateClass, ) +from typing import Literal, NamedTuple + from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import StateType +from homeassistant.helpers.typing import DiscoveryInfoType + from homeassistant.const import ( ATTR_ATTRIBUTION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, @@ -26,28 +35,27 @@ CONF_SCAN_INTERVAL, DEGREE, PERCENTAGE, - UV_INDEX, - UnitOfLength, - UnitOfPrecipitationDepth, UnitOfPressure, UnitOfSpeed, UnitOfTemperature, + UnitOfLength, UnitOfVolumetricFlux, + UnitOfPrecipitationDepth, + UV_INDEX, ) -from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import DiscoveryInfoType, StateType from .const import ( - ALL_CONDITIONS, DEFAULT_SCAN_INTERVAL, DOMAIN, ENTRY_WEATHER_COORDINATOR, - PW_PLATFORM, + ALL_CONDITIONS, PW_PLATFORMS, + PW_PLATFORM, PW_PREVPLATFORM, PW_ROUND, ) + + from .weather_update_coordinator import WeatherUpdateCoordinator _LOGGER = logging.getLogger(__name__) @@ -778,6 +786,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up Pirate Weather sensor entities based on a config entry.""" + domain_data = hass.data[DOMAIN][config_entry.entry_id] name = domain_data[CONF_NAME] @@ -984,6 +993,7 @@ def extra_state_attributes(self): @property def native_value(self) -> StateType: """Return the state of the device.""" + self.update_unit_of_measurement() if self.type == "alerts": @@ -1125,25 +1135,6 @@ def get_state(self, data): ]: state = state * 3.6 - if self.type in [ - "uv_index", - ]: - if state < 0 or state > 100: - _LOGGER.warning( - "UV Index is reporting %s which is outside the expected range! Setting UV Index to -1! Please report this issue to https://github.com/Pirate-Weather/pirateweather if not already reported.", - state, - ) - state = -1 - if self.type in [ - "cloud_cover", - ]: - if state > 100: - _LOGGER.warning( - "Cloud cover is reporting %s which is above 100%! Setting cloud cover to 100%! Please report this issue to https://github.com/Pirate-Weather/pirateweather if not already reported.", - state, - ) - state = 100 - if self.type in [ "dew_point", "temperature", @@ -1206,4 +1197,4 @@ def convert_to_camel(data): """ components = data.split("_") capital_components = "".join(x.title() for x in components[1:]) - return f"{components[0]}{capital_components}" + return f"{components[0]}{capital_components}" \ No newline at end of file