feat(midsussex_gov_uk): Add replacement source script and documentation#5083
feat(midsussex_gov_uk): Add replacement source script and documentation#5083Gdkkauowj33 wants to merge 1 commit intomampfes:masterfrom
Conversation
|
Mid Sussex changed to a new service provider, which presented a completely new web site and sequencing, hence fix required. |
|
Appears to work fine, thanks |
|
For the less capable amongst us, what do we need to do to get Mid Sussex working again? |
|
You can either wait until the changes are merged and then update as you would normally. Or you can copy the file from the link below. It’s possible that you might need to update your address settings in the GUI. https://github.com/mampfes/hacs_waste_collection_schedule/blob/7b9bf2d72a5594706ee0cf77d55cc906be193516/custom_components/waste_collection_schedule/waste_collection_schedule/source/midsussex_gov_uk.py |
|
I think I had to delete the existing entity then add the integration as if new (after copying the updated py file and restarting HA) either because the source fields changed or because I was incompetent. |
5ila5
left a comment
There was a problem hiding this comment.
You should either keep the __init__ variables or write a migration. So at least for configuration that used house_number street and postcode the source works again without reconfiguration.
a migritation would look like that:
diff --git a/custom_components/waste_collection_schedule/const.py b/custom_components/waste_collection_schedule/const.py
index 48e428da..f728d089 100644
--- a/custom_components/waste_collection_schedule/const.py
+++ b/custom_components/waste_collection_schedule/const.py
@@ -8,7 +8,7 @@ DOMAIN: Final = "waste_collection_schedule"
UPDATE_SENSORS_SIGNAL: Final = "wcs_update_sensors_signal"
CONFIG_VERSION: Final = 2
-CONFIG_MINOR_VERSION: Final = 10
+CONFIG_MINOR_VERSION: Final = 11
# Config var names
CONF_SOURCES: Final = "sources"
diff --git a/custom_components/waste_collection_schedule/init_ui.py b/custom_components/waste_collection_schedule/init_ui.py
index 2bc448cf..44d711ae 100644
--- a/custom_components/waste_collection_schedule/init_ui.py
+++ b/custom_components/waste_collection_schedule/init_ui.py
@@ -284,6 +284,23 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
if "name" in new_data["args"]:
del new_data["args"]["name"]
+ if config_entry.version < 2 or (
+ config_entry.version == 2 and config_entry.minor_version < 11
+ ):
+ # Migrate from birmingham_gov_uk to roundlookup_uk
+ if new_data.get("name", "") == "midsussex_gov_uk":
+ _LOGGER.debug("Migrating midsussex_gov_uk to new configuration")
+
+ new_data["args"]["number"] = new_data["args"].get("house_number")
+ new_data["args"]["post_code"] = new_data["args"].get("uprn")
+
+ if "house_number" in new_data["args"]:
+ del new_data["args"]["house_number"]
+ if "house_name" in new_data["args"]:
+ del new_data["args"]["house_name"]
+ if "address" in new_data["args"]:
+ del new_data["args"]["address"]
+
hass.config_entries.async_update_entry(
config_entry,
data=new_data,| raise SourceArgumentException( | ||
| "Address not found. Check house name/number and postcode.", | ||
| argument="number" | ||
| ) |
There was a problem hiding this comment.
Please look at the classes before you use them
class SourceArgumentException(Exception):
def __init__(self, argument: str, message: str) -> None:so this code generates a SourceArgumentException.__init__() got multiple values for argument 'argument'
I'd suggest raising a SourceArgumentNotFound here
| raise SourceArgumentException( | |
| "Address not found. Check house name/number and postcode.", | |
| argument="number" | |
| ) | |
| raise SourceArgumentNotFound( | |
| "number", | |
| self._number | |
| ) |
|
|
||
| if not collection_entries: | ||
| if soup3.find(string=lambda t: t and "not available" in t.lower()): | ||
| return [] # Return empty list if schedule is unavailable |
There was a problem hiding this comment.
Do not return an empty list as this will just fail silently. Raise an exception here so something shows up in the logs
| try: | ||
| collection_date = datetime.datetime.strptime(date_str, DATE_FORMAT).date() | ||
| except ValueError: | ||
| print(f"Skipping entry with unparsable date format: {date_str}") |
There was a problem hiding this comment.
If you want this to show up in the HA logs, you need to use the logging library
Test Output
Testing source midsussex_gov_uk ...
found 10 entries for Test Case 1: 23 High Street
found 10 entries for Test Case 2: Hapstead Hall
found 10 entries for Test Case 3: The Gardeners Arms