Skip to content

Commit

Permalink
Minor code patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 28, 2021
1 parent bcf3aa9 commit fdbd4d6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions custom_components/gismeteo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions custom_components/gismeteo/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2018, Vladimir Maksimenko <vl.maksime@gmail.com>
# Copyright (c) 2019-2021, Andrey "Limych" Khrolenok <andrey@khrolenok.ru>
#
# Version 3.0
# Version 3.0.1
"""Cache controller."""

import logging
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions custom_components/gismeteo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
31 changes: 15 additions & 16 deletions custom_components/gismeteo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -74,7 +76,6 @@

ATTR_SUNRISE = "sunrise"
ATTR_SUNSET = "sunset"
ATTR_LABEL = "label"

ATTR_WEATHER_CONDITION = ATTR_FORECAST_CONDITION
ATTR_WEATHER_CLOUDINESS = "cloudiness"
Expand All @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions custom_components/gismeteo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ATTR_ATTRIBUTION,
ATTR_DEVICE_CLASS,
ATTR_ICON,
ATTR_NAME,
ATTR_UNIT_OF_MEASUREMENT,
CONF_API_KEY,
CONF_MONITORED_CONDITIONS,
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fdbd4d6

Please sign in to comment.