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

[bug] notification sensor doesn't get updated #60

Open
rkrkrk0987 opened this issue Dec 11, 2024 · 4 comments
Open

[bug] notification sensor doesn't get updated #60

rkrkrk0987 opened this issue Dec 11, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@rkrkrk0987
Copy link

notification sensor doesn't get updated

there are no errors in home-assistant.log related to this component

to have better idea i extended log with log.info in in __init__.py number of notifications in fetch_data():

                _LOGGER.debug(f"INIT Coordinator fetch_data returning: {return_data}")
                _LOGGER.info(f"INIT Coordinator fetch_data returning length: {len(notifications)}")

and in sensor.py in class EduPageNotificationSensor state(self)

        """Return state."""
        _LOGGER.info("SENSOR state %s",len(self._notifications))
        return len(self._notifications)

and after while it is no longer the same number

2024-12-11 17:03:18.847 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 199
2024-12-11 17:03:18.851 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
@rine77 rine77 added the bug Something isn't working label Dec 11, 2024
@rine77 rine77 changed the title notification sensor doesn't get updated [bug] notification sensor doesn't get updated Dec 11, 2024
@rine77
Copy link
Owner

rine77 commented Dec 11, 2024

thanks for your feedback! I'm trying to reproduce and get an idea.

@rine77 rine77 self-assigned this Dec 11, 2024
@rkrkrk0987
Copy link
Author

let me know if i can provide you with more details
in this case 3 times it was able to refresh data (30min as you defined) and 4th time sensor haven't received new data, and was working only with old data... and haven't recovered, so it is still unable to receive current data

so it was like:

2024-12-11 14:32:26.170 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 198
2024-12-11 14:32:26.216 INFO (MainThread) [homeassistant.components.calendar] Setting up homeassistantedupage.calendar
2024-12-11 14:32:26.222 INFO (MainThread) [homeassistant.components.sensor] Setting up homeassistantedupage.sensor
2024-12-11 14:32:26.256 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 14:32:35.506 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 198
2024-12-11 14:32:35.510 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 15:02:43.803 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 198
2024-12-11 15:02:43.807 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 15:32:52.240 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 198
2024-12-11 15:32:52.244 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 16:03:01.634 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 199
2024-12-11 16:03:01.639 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 16:33:10.580 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 199
2024-12-11 16:33:10.584 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...
2024-12-11 17:03:18.847 INFO (MainThread) [custom_components.homeassistant_edupage] INIT Coordinator fetch_data returning length: 199
2024-12-11 17:03:18.851 INFO (MainThread) [custom_components.homeassistant_edupage] SENSOR state 198
...

@rine77
Copy link
Owner

rine77 commented Dec 17, 2024

I still dont have no update problem. The data is correct in my case!

@rkrkrk0987
Copy link
Author

rkrkrk0987 commented Jan 21, 2025

sorry for late reply, from my point of view without any knowledge of custom components, if you look at sensor.py

class EduPageNotificationSensor(CoordinatorEntity, SensorEntity):
    """Subject sensor entity for a specific student."""

    def __init__(self, coordinator, student_id, student_name, notifications):
        """Initialize the sensor."""
        super().__init__(coordinator)

        self._notifications = notifications
...

self._notifications is only assigned in __init__ function
and referencing in all functions... but during update __init__ function isn't called, just specific function eg: extra_state_attributes

for me, problem was solved by adding:

        notifications = self.coordinator.data.get("notifications", [])

like:

    @property
    def extra_state_attributes(self):
        """Return additional attributes."""
        notifications = self.coordinator.data.get("notifications", [])
        attributes = {}
        attributes = {
            "student": self.coordinator.data.get("student", {}),
            "unique_id": self._unique_id
            }

        for i, event in enumerate(notifications):
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants