Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support of reconfiguration for HA 2024.7 #300

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions custom_components/ev_smart_charging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions custom_components/ev_smart_charging/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +126,10 @@
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")

Check warning on line 131 in custom_components/ev_smart_charging/config_flow.py

View check run for this annotation

Codecov / codecov/patch

custom_components/ev_smart_charging/config_flow.py#L131

Added line #L131 was not covered by tests

if error is not None:
self._errors[error[0]] = error[1]

Expand Down
8 changes: 5 additions & 3 deletions custom_components/ev_smart_charging/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ev_smart_charging/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
7 changes: 5 additions & 2 deletions scripts/pytest_all_ha_versions_python312
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading