Skip to content

Commit

Permalink
maint: Move coordinator setup code to new _async_setup method
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Aug 6, 2024
1 parent 3444f18 commit 4cfb3d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion custom_components/ms365_teams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: MS365ConfigEntry):
)

if is_authenticated and permissions and permissions != TOKEN_FILE_MISSING:
_LOGGER.debug("do setup")
_LOGGER.debug("Do setup")
check_token = await _async_check_token(hass, account, entity_name)
if check_token:
coordinator, sensors, platforms = await async_do_setup(hass, entry, account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, account):
self._entry = entry
self._account = account
self._entity_name = entry.data[CONF_ENTITY_NAME]
self._keys = []
self.keys = []
self._data = {}
self._chat_members = {}

async def async_setup_entries(self):
async def _async_setup(self):
"""Do the initial setup of the entities."""
status_keys = await self._async_status_sensors()
chat_keys = self._chat_sensors()
self._keys = chat_keys + status_keys
return self._keys
self.keys = chat_keys + status_keys
return self.keys

async def _async_status_sensors(self):
keys = []
Expand Down Expand Up @@ -110,10 +110,10 @@ def _chat_sensors(self):

async def _async_update_data(self):
_LOGGER.debug(
"Doing %s email update(s) for: %s", len(self._keys), self._entity_name
"Doing %s email update(s) for: %s", len(self.keys), self._entity_name
)

for key in self._keys:
for key in self.keys:
entity_type = key[CONF_ENTITY_TYPE]
if entity_type == SENSOR_TEAMS_CHAT:
await self._async_teams_chat_update(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ async def async_do_setup(hass: HomeAssistant, entry: ConfigEntry, account):

_LOGGER.debug("Sensor setup - start")
sensor_coordinator = MS365SensorCoordinator(hass, entry, account)
sensor_keys = await sensor_coordinator.async_setup_entries()
if sensor_keys:
await sensor_coordinator.async_config_entry_first_refresh()
_LOGGER.debug("Email setup - finish")
return sensor_coordinator, sensor_keys, PLATFORMS
await sensor_coordinator.async_config_entry_first_refresh()
_LOGGER.debug("Sensor setup - finish")
return sensor_coordinator, sensor_coordinator.keys, PLATFORMS

0 comments on commit 4cfb3d5

Please sign in to comment.