Use super constructor self.config_entry in enphase_envoy coordinator (#133718)
parent
a3fab094c3
commit
a3fad89d0d
|
@ -37,6 +37,7 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
|
||||
envoy_serial_number: str
|
||||
envoy_firmware: str
|
||||
config_entry: EnphaseConfigEntry
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, envoy: Envoy, entry: EnphaseConfigEntry
|
||||
|
@ -44,7 +45,6 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
"""Initialize DataUpdateCoordinator for the envoy."""
|
||||
self.envoy = envoy
|
||||
entry_data = entry.data
|
||||
self.entry = entry
|
||||
self.username = entry_data[CONF_USERNAME]
|
||||
self.password = entry_data[CONF_PASSWORD]
|
||||
self._setup_complete = False
|
||||
|
@ -107,7 +107,7 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
await envoy.setup()
|
||||
assert envoy.serial_number is not None
|
||||
self.envoy_serial_number = envoy.serial_number
|
||||
if token := self.entry.data.get(CONF_TOKEN):
|
||||
if token := self.config_entry.data.get(CONF_TOKEN):
|
||||
with contextlib.suppress(*INVALID_AUTH_ERRORS):
|
||||
# Always set the username and password
|
||||
# so we can refresh the token if needed
|
||||
|
@ -136,9 +136,9 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
# as long as the token is valid
|
||||
_LOGGER.debug("%s: Updating token in config entry from auth", self.name)
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.entry,
|
||||
self.config_entry,
|
||||
data={
|
||||
**self.entry.data,
|
||||
**self.config_entry.data,
|
||||
CONF_TOKEN: envoy.auth.token,
|
||||
},
|
||||
)
|
||||
|
@ -189,7 +189,7 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
)
|
||||
# reload the integration to get all established again
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||
self.hass.config_entries.async_reload(self.config_entry.entry_id)
|
||||
)
|
||||
# remember firmware version for next time
|
||||
self.envoy_firmware = envoy.firmware
|
||||
|
|
|
@ -7,12 +7,7 @@ rules:
|
|||
status: done
|
||||
comment: fixed 1 minute cycle based on Enphase Envoy device characteristics
|
||||
brands: done
|
||||
common-modules:
|
||||
status: done
|
||||
comment: |
|
||||
In coordinator.py, you set self.entry = entry, while after the super constructor,
|
||||
you can access the entry via self.config_entry (you would have to overwrite the
|
||||
type to make sure you don't have to assert not None every time)done
|
||||
common-modules: done
|
||||
config-flow-test-coverage:
|
||||
status: todo
|
||||
comment: |
|
||||
|
|
Loading…
Reference in New Issue