Skip to content

Commit

Permalink
fix: Add support for legacy cities
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh committed Sep 11, 2024
1 parent 01667cf commit 1de75ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions custom_components/ims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Extract list of int from forecast days/ hours string if present
# _LOGGER.warning('forecast_days_type: ' + str(type(forecast_days)))

unique_location = f"ims-{language}-{city['lid']}"
is_legacy_city = False
if isinstance(city, int | str):
is_legacy_city = True

city_id = city if is_legacy_city else city['lid']

unique_location = f"ims-{language}-{city_id}"

hass.data.setdefault(DOMAIN, {})
# If coordinator already exists for this API key, we'll use that, otherwise
Expand All @@ -66,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
else:
weather_coordinator = WeatherUpdateCoordinator(
city['lid'], language, timedelta(minutes=ims_scan_int), hass
city_id, language, timedelta(minutes=ims_scan_int), hass
)
hass.data[DOMAIN][unique_location] = weather_coordinator
# _LOGGER.warning('New Coordinator')
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ims/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ async def async_step_init(self, user_input=None):
CONF_CITY,
default=self.config_entry.options.get(
CONF_CITY,
self.config_entry.data.get(CONF_CITY, cities_data["1"]),
self.config_entry.data.get(CONF_CITY, 1),
),
): int,
vol.Optional(
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/GuyKh/ims-custom-component/issues",
"requirements": ["weatheril>=0.32.0"],
"version": "0.1.27"
"version": "0.1.28"
}
7 changes: 6 additions & 1 deletion custom_components/ims/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,18 @@ async def async_setup_entry(
city = domain_data[CONF_CITY]
forecast_mode = domain_data[CONF_MODE]

is_legacy_city = False
if isinstance(city, int | str):
is_legacy_city = True


unique_id = f"{config_entry.unique_id}"

# Round Output
output_round = "No"

ims_weather = IMSWeather(
name, unique_id, forecast_mode, weather_coordinator, city["name"], output_round
name, unique_id, forecast_mode, weather_coordinator, city if is_legacy_city else city["name"], output_round
)

async_add_entities([ims_weather], False)
Expand Down

0 comments on commit 1de75ed

Please sign in to comment.