diff --git a/custom_components/ev_smart_charging/__init__.py b/custom_components/ev_smart_charging/__init__.py index 3df9954..dd25012 100644 --- a/custom_components/ev_smart_charging/__init__.py +++ b/custom_components/ev_smart_charging/__init__.py @@ -61,23 +61,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # If the name of the integration (config_entry.title) has changed, # update the device name. - entity_registry: EntityRegistry = async_entity_registry_get(hass) - all_entities = async_entries_for_config_entry(entity_registry, entry.entry_id) - if all_entities: - device_id = all_entities[0].device_id - device_registry: DeviceRegistry = async_device_registry_get(hass) - device: DeviceEntry = device_registry.async_get(device_id) - if device: - if device.name_by_user is not None: - if entry.title != device.name_by_user: - device_registry.async_update_device( - device.id, name_by_user=entry.title - ) - else: - if entry.title != device.name: - device_registry.async_update_device( - device.id, name_by_user=entry.title - ) + if MAJOR_VERSION < 2024 or (MAJOR_VERSION == 2024 and MINOR_VERSION <= 6): + # Does not work with HA 2024.7 + entity_registry: EntityRegistry = async_entity_registry_get(hass) + all_entities = async_entries_for_config_entry(entity_registry, entry.entry_id) + if all_entities: + device_id = all_entities[0].device_id + device_registry: DeviceRegistry = async_device_registry_get(hass) + device: DeviceEntry = device_registry.async_get(device_id) + if device: + if device.name_by_user is not None: + if entry.title != device.name_by_user: + device_registry.async_update_device( + device.id, name_by_user=entry.title + ) + else: + if entry.title != device.name: + device_registry.async_update_device( + device.id, name_by_user=entry.title + ) return True diff --git a/custom_components/ev_smart_charging/config_flow.py b/custom_components/ev_smart_charging/config_flow.py index 539be36..bfa4cde 100644 --- a/custom_components/ev_smart_charging/config_flow.py +++ b/custom_components/ev_smart_charging/config_flow.py @@ -4,6 +4,7 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.const import MAJOR_VERSION, MINOR_VERSION from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv @@ -125,6 +126,10 @@ async def async_step_init(self, user_input) -> FlowResult: if user_input is not None: # process user_input error = FlowValidator.validate_step_user(self.hass, user_input) + if MAJOR_VERSION > 2024 or (MAJOR_VERSION == 2024 and MINOR_VERSION >= 7): + # Does not work with HA 2024.7 + error = ("base", "reconfiguration_not_supported") + if error is not None: self._errors[error[0]] = error[1] diff --git a/custom_components/ev_smart_charging/coordinator.py b/custom_components/ev_smart_charging/coordinator.py index ad5fa4e..9bad2e6 100644 --- a/custom_components/ev_smart_charging/coordinator.py +++ b/custom_components/ev_smart_charging/coordinator.py @@ -187,9 +187,11 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None: async_track_time_change(hass, self.update_hourly, minute=0, second=0) ) # Listen for changes to the device. - self.listeners.append( - hass.bus.async_listen(EVENT_DEVICE_REGISTRY_UPDATED, self.device_updated) - ) + if MAJOR_VERSION < 2024 or (MAJOR_VERSION == 2024 and MINOR_VERSION <= 6): + # Does not work with HA 2024.7 + self.listeners.append( + hass.bus.async_listen(EVENT_DEVICE_REGISTRY_UPDATED, self.device_updated) + ) def unsubscribe_listeners(self): """Unsubscribed to listeners""" diff --git a/custom_components/ev_smart_charging/translations/en.json b/custom_components/ev_smart_charging/translations/en.json index d6481cc..43034b0 100644 --- a/custom_components/ev_smart_charging/translations/en.json +++ b/custom_components/ev_smart_charging/translations/en.json @@ -47,7 +47,8 @@ "ev_target_soc_not_found": "EV Target SOC entity not found.", "ev_target_soc_invalid_data": "The Target SOC entity gives invalid data.", "charger_control_switch_not_found": "Charger control switch entity not found.", - "charger_control_switch_not_switch": "Charger control switch entity is not a switch." + "charger_control_switch_not_switch": "Charger control switch entity is not a switch.", + "reconfiguration_not_supported": "Reconfiguration not supported for HA 2024.7 or newer." } } } \ No newline at end of file diff --git a/scripts/pytest_all_ha_versions_python312 b/scripts/pytest_all_ha_versions_python312 index 88ae5c1..d22be3e 100644 --- a/scripts/pytest_all_ha_versions_python312 +++ b/scripts/pytest_all_ha_versions_python312 @@ -51,5 +51,8 @@ run_next_test "auto" pip3 install -qq homeassistant==2024.6.4 pytest-homeassistant-custom-component==0.13.136 run_next_test "auto" -pip3 install -qq homeassistant==2024.7.2 pytest-homeassistant-custom-component==0.13.146 -run_next_test "auto" +# pip3 install -qq homeassistant==2024.7.2 pytest-homeassistant-custom-component==0.13.146 +# run_next_test "auto" + +# pip3 install -qq homeassistant==2024.7.3 pytest-homeassistant-custom-component==0.13.147 +# run_next_test "auto"