Skip to content

Commit

Permalink
fixed exclude data
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasJoKuJonas committed Oct 18, 2024
1 parent c51ed3f commit c3d0a23
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions custom_components/webuntis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def __init__(
self.filter_subjects = config.options["filter_subjects"]

self.exclude_data = config.options["exclude_data"]
self.exclude_data_run = []

self.filter_description = config.options["filter_description"]
self.generate_json = config.options["generate_json"]

Expand Down Expand Up @@ -269,6 +271,10 @@ async def async_update(self, now: datetime | None = None) -> None:
async def _async_status_request(self) -> None:
"""Request status and update properties."""

if self.exclude_data_run:
for i in self.exclude_data_run:
self.exclude_data_(i)

login_error = await self._hass.async_add_executor_job(self.webuntis_login)

if login_error:
Expand Down Expand Up @@ -945,12 +951,9 @@ def get_lesson_json(self, lesson, force=False, output_str=True) -> str:
]
except (OSError, errors.RemoteError) as error:
if "no right for getTeachers()" in str(error):
self.exclude_data_("teachers")
_LOGGER.info(
"No rights for getTeachers() for '%s@%s', getTeachers is now on blacklist",
self.school,
self.username,
)
self.exclude_data_run.append("teachers")
self.exclude_data.append("teachers")

except:
pass

Expand Down Expand Up @@ -1019,12 +1022,9 @@ def get_lesson_for_notify(self, lesson) -> str:
]
except (OSError, errors.RemoteError) as error:
if "no right for getTeachers()" in str(error):
self.exclude_data_("teachers")
_LOGGER.info(
"No rights for getTeachers() for '%s@%s', getTeachers is now on blacklist",
self.school,
self.username,
)
self.exclude_data_run.append("teachers")
self.exclude_data.append("teachers")

except:
pass

Expand All @@ -1033,12 +1033,21 @@ def get_lesson_for_notify(self, lesson) -> str:
def exclude_data_(self, data):
"""adds data to exclude_data list"""

self.exclude_data_run.remove(data)

new_options = {**self._config.options}
new_options["exclude_data"] = [*new_options["exclude_data"], data]

self._hass.config_entries.async_update_entry(self._config, options=new_options)
self.exclude_data.append(data)

_LOGGER.info(
"No rights for %s, is now on blacklist '%s@%s'",
data,
self.school,
self.username,
)

async def update_notify(self):
"""Update data and notify"""

Expand Down

0 comments on commit c3d0a23

Please sign in to comment.