Skip to content

Commit

Permalink
Another fix for Monitored Conditions backward compatibility (#84)
Browse files Browse the repository at this point in the history
* Another fix for Monitored Conditions backward compatibility

* Remove SonarCloud from readme

* Clean __init__
  • Loading branch information
GuyKh committed Jan 29, 2024
1 parent f18b65b commit 93f30c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.1.23

* Another Fix for Monitored Condition backward compatibility

## v0.1.22

* Fix Monitored Condition backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# ims-custom-component

[![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg)](https://github.com/hacs/integration) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=techblog_ims-custom-component&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=techblog_ims-custom-component)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg)](https://github.com/hacs/integration)



Expand Down
12 changes: 7 additions & 5 deletions custom_components/ims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
IMS_PLATFORMS,
IMS_PLATFORM,
IMS_PREVPLATFORM,
DEFAULT_LANGUAGE,
FORECAST_MODE_HOURLY,
)

from .weather_update_coordinator import WeatherUpdateCoordinator
Expand All @@ -45,9 +47,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up IMS Weather as config entry."""
name = entry.data[CONF_NAME]
city = _get_config_value(entry, CONF_CITY)
forecast_mode = _get_config_value(entry, CONF_MODE)
forecast_mode = _get_config_value(entry, CONF_MODE, FORECAST_MODE_HOURLY)
images_path = _get_config_value(entry, CONF_IMAGES_PATH)
language = _get_config_value(entry, CONF_LANGUAGE)
language = _get_config_value(entry, CONF_LANGUAGE, DEFAULT_LANGUAGE)
ims_entity_platform = _get_config_value(entry, IMS_PLATFORM)
ims_scan_int = entry.data[CONF_UPDATE_INTERVAL]
conditions = _get_config_value(entry, CONF_MONITORED_CONDITIONS)
Expand Down Expand Up @@ -142,20 +144,20 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True


def _get_config_value(config_entry: ConfigEntry, key: str) -> Any:
def _get_config_value(config_entry: ConfigEntry, key: str, default = None) -> Any:
if config_entry.options:
val = config_entry.options.get(key)
if val:
return val
else:
_LOGGER.warning("Key %s is missing from config_entry.options", key)
return None
return default
val = config_entry.data.get(key)
if val:
return val
else:
_LOGGER.warning("Key %s is missing from config_entry.data", key)
return None
return default



Expand Down
2 changes: 1 addition & 1 deletion custom_components/ims/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/t0mer/ims-custom-component/issues",
"requirements": ["weatheril>=0.32.0"],
"version": "0.1.22"
"version": "0.1.23"
}
4 changes: 4 additions & 0 deletions custom_components/ims/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ async def async_setup_entry(
# Add IMS Sensors
sensors: list[ImsSensor] = []

if conditions is None:
# If a problem happens - create all sensors
conditions = SENSOR_DESCRIPTIONS_KEYS

for condition in conditions:
description = SENSOR_DESCRIPTIONS_DICT[condition]
sensors.append(ImsSensor(weather_coordinator, description))
Expand Down

0 comments on commit 93f30c2

Please sign in to comment.