diff --git a/.github/settings.yml b/.github/settings.yml index e7f87a5..6a27bed 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -5,8 +5,8 @@ repository: has_wiki: false has_downloads: false default_branch: master + allow_merge_commit: true allow_squash_merge: true - allow_merge_commit: false allow_rebase_merge: false labels: - name: "breaking" diff --git a/custom_components/gismeteo/__init__.py b/custom_components/gismeteo/__init__.py index 8446e93..696345a 100644 --- a/custom_components/gismeteo/__init__.py +++ b/custom_components/gismeteo/__init__.py @@ -176,8 +176,6 @@ async def _async_update_data(self): try: async with timeout(10): await self.gismeteo.async_update() - current = self.gismeteo.current + return self.gismeteo.current except (ApiError, ClientConnectorError) as error: raise UpdateFailed(error) from error - - return current diff --git a/custom_components/gismeteo/cache.py b/custom_components/gismeteo/cache.py index d3de5ed..308ff94 100644 --- a/custom_components/gismeteo/cache.py +++ b/custom_components/gismeteo/cache.py @@ -1,7 +1,7 @@ # Copyright (c) 2018, Vladimir Maksimenko # Copyright (c) 2019-2021, Andrey "Limych" Khrolenok # -# Version 3.0 +# Version 3.0.1 """Cache controller.""" import logging @@ -70,8 +70,7 @@ def read_cache(self, file_name): file_path = self._get_file_path(file_name) _LOGGER.debug("Read cache file %s", file_path) if self.is_cached(file_name): - with open(file_path) as file: - content = file.read() + content = open(file_path).read() else: content = None diff --git a/custom_components/gismeteo/config_flow.py b/custom_components/gismeteo/config_flow.py index f95b70c..4a2603d 100644 --- a/custom_components/gismeteo/config_flow.py +++ b/custom_components/gismeteo/config_flow.py @@ -45,9 +45,8 @@ async def async_step_import(self, platform_config): Special type of import, we're not actually going to store any data. Instead, we're going to rely on the values that are in config file. """ - for entry in self._async_current_entries(): - if entry.source == "import": - return self.async_abort(reason="single_instance_allowed") + if self._async_current_entries(): + return self.async_abort(reason="single_instance_allowed") return self.async_create_entry(title="configuration.yaml", data=platform_config) diff --git a/custom_components/gismeteo/const.py b/custom_components/gismeteo/const.py index 5e08b46..cba698e 100644 --- a/custom_components/gismeteo/const.py +++ b/custom_components/gismeteo/const.py @@ -16,11 +16,13 @@ from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_ICON, + ATTR_NAME, ATTR_UNIT_OF_MEASUREMENT, DEGREE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, + LENGTH_MILLIMETERS, PRESSURE_HPA, SPEED_METERS_PER_SECOND, TEMP_CELSIUS, @@ -74,7 +76,6 @@ ATTR_SUNRISE = "sunrise" ATTR_SUNSET = "sunset" -ATTR_LABEL = "label" ATTR_WEATHER_CONDITION = ATTR_FORECAST_CONDITION ATTR_WEATHER_CLOUDINESS = "cloudiness" @@ -98,86 +99,84 @@ PRECIPITATION_AMOUNT = (0, 2, 6, 16) -LENGTH_MILLIMETERS: str = "mm" - SENSOR_TYPES = { "weather": { ATTR_DEVICE_CLASS: None, ATTR_ICON: None, - ATTR_LABEL: "Condition", + ATTR_NAME: "Condition", ATTR_UNIT_OF_MEASUREMENT: None, }, "temperature": { ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_ICON: None, - ATTR_LABEL: "Temperature", + ATTR_NAME: "Temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, "wind_speed": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-windy", - ATTR_LABEL: "Wind speed", + ATTR_NAME: "Wind speed", ATTR_UNIT_OF_MEASUREMENT: SPEED_METERS_PER_SECOND, }, "wind_bearing": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-windy", - ATTR_LABEL: "Wind bearing", + ATTR_NAME: "Wind bearing", ATTR_UNIT_OF_MEASUREMENT: DEGREE, }, "humidity": { ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY, ATTR_ICON: None, - ATTR_LABEL: "Humidity", + ATTR_NAME: "Humidity", ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, }, "pressure": { ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE, ATTR_ICON: None, - ATTR_LABEL: "Pressure", + ATTR_NAME: "Pressure", ATTR_UNIT_OF_MEASUREMENT: PRESSURE_HPA, }, "clouds": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-partly-cloudy", - ATTR_LABEL: "Cloud coverage", + ATTR_NAME: "Cloud coverage", ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, }, "rain": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-rainy", - ATTR_LABEL: "Rain", + ATTR_NAME: "Rain", ATTR_UNIT_OF_MEASUREMENT: LENGTH_MILLIMETERS, }, "snow": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-snowy", - ATTR_LABEL: "Snow", + ATTR_NAME: "Snow", ATTR_UNIT_OF_MEASUREMENT: LENGTH_MILLIMETERS, }, "storm": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-lightning", - ATTR_LABEL: "Storm", + ATTR_NAME: "Storm", ATTR_UNIT_OF_MEASUREMENT: None, }, "geomagnetic": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:magnet-on", - ATTR_LABEL: "Geomagnetic field", + ATTR_NAME: "Geomagnetic field", ATTR_UNIT_OF_MEASUREMENT: "", }, "water_temperature": { ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_ICON: None, - ATTR_LABEL: "Water Temperature", + ATTR_NAME: "Water Temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, } FORECAST_SENSOR_TYPE = { ATTR_DEVICE_CLASS: None, ATTR_ICON: None, - ATTR_LABEL: "Forecast", + ATTR_NAME: "Forecast", ATTR_UNIT_OF_MEASUREMENT: None, } diff --git a/custom_components/gismeteo/sensor.py b/custom_components/gismeteo/sensor.py index 0368c37..2b67f15 100644 --- a/custom_components/gismeteo/sensor.py +++ b/custom_components/gismeteo/sensor.py @@ -18,6 +18,7 @@ ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, ATTR_ICON, + ATTR_NAME, ATTR_UNIT_OF_MEASUREMENT, CONF_API_KEY, CONF_MONITORED_CONDITIONS, @@ -31,7 +32,6 @@ from . import ATTRIBUTION, DOMAIN, GismeteoDataUpdateCoordinator from .const import ( - ATTR_LABEL, ATTR_WEATHER_CLOUDINESS, ATTR_WEATHER_GEOMAGNETIC_FIELD, ATTR_WEATHER_PRECIPITATION_AMOUNT, @@ -143,7 +143,7 @@ def _gismeteo(self) -> Gismeteo: @property def name(self): """Return the name of the sensor.""" - return f"{self._name} {SENSOR_TYPES[self.kind][ATTR_LABEL]}" + return f"{self._name} {SENSOR_TYPES[self.kind][ATTR_NAME]}" @property def unique_id(self):