custom_components/best_bottrop_garbage_collection/sensor.py
def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        _LOGGER.debug(
            "I am %s, callback function called",
            self._attr_unique_id,
        )

        if self._trash_type_id == "A2954658" or self._trash_type_id == "43806A8A":
            _LOGGER.debug("Container oder Weihnachten!")
            return

        if self._trash_type_id == "3F14EDC7":
            _LOGGER.debug("GELBE TONNE!")
        # Now find my JSON
        # sub_list_data: lists
        # the data is structured as a dict. The key is the street_id.
        # That data to that key is the JSON-dict.
        if (self.coordinator.data is not None) and (
            self._street_id in self.coordinator.data
        ):
            street_json = self.coordinator.data[self._street_id]
            # iterate throught the JSON of our street_id!
            for next_collection in street_json:
                # now find the resulting trash type
                if self._trash_type_id == next_collection["trashType"]:
                    # next collection date for the trashtype found
                    # the format is dd.mm.yyyy
                    ldate = next_collection["formattedDate"].split(".", 3)
                    next_date = date(int(ldate[2]), int(ldate[1]), int(ldate[0]))
                    _LOGGER.debug("Next date %s", next_date)
                    _LOGGER.debug("Today  %s", datetime.today())
                    _LOGGER.debug("Ignore until  %s", self._ignore)

                    if (self._ignore is not None) and (next_date <= self._ignore):
                        _LOGGER.debug("SKIPPING")
                        continue

                    diff_date = next_date - date.today()

                    _LOGGER.debug("Diff  %s", diff_date)

                    self._next_date = (
                        datetime(next_date.year, next_date.month, next_date.day)
                        .astimezone()
                        .isoformat()
                    )

                    _LOGGER.debug(
                        "Updateing native value: %s",
                        str(diff_date.days),
                    )

                    if diff_date.days >= 0:
                        # if the diff date == 0, then it is/was today.
                        self._state = diff_date.days
                        self._days = diff_date.days
                    else:
                        self._state = None

                    self._message = next_collection["message"]

                    break
        self.async_write_ha_state()
Handle updated data from the coordinator.
Handle updated data from the coordinator.
Handle updated data from the coordinator .
def _handle_coordinator_update(self) -> None:
        _LOGGER.debug(
            "I am %s, callback function called",
            self._attr_unique_id,
        )
        if self._trash_type_id == "A2954658" or self._trash_type_id == "43806A8A":
            _LOGGER.debug("Container oder Weihnachten!")
            return
        if self._trash_type_id == "3F14EDC7":
            _LOGGER.debug("GELBE TONNE!")
        if (self.coordinator.data is not None) and (
            self._street_id in self.coordinator.data
        ):
            street_json = self.coordinator.data[self._street_id]
            for next_collection in street_json:
                if self._trash_type_id == next_collection["trashType"]:
                    ldate = next_collection["formattedDate"].split(".", 3)
                    next_date = date(int(ldate[2]), int(ldate[1]), int(ldate[0]))
                    _LOGGER.debug("Next date %s", next_date)
                    _LOGGER.debug("Today  %s", datetime.today())
                    _LOGGER.debug("Ignore until  %s", self._ignore)
                    if (self._ignore is not None) and (next_date <= self._ignore):
                        _LOGGER.debug("SKIPPING")
                        continue
                    diff_date = next_date - date.today()
                    _LOGGER.debug("Diff  %s", diff_date)
                    self._next_date = (
                        datetime(next_date.year, next_date.month, next_date.day)
                        .astimezone()
                        .isoformat()
                    )
                    _LOGGER.debug(
                        "Updateing native value: %s",
                        str(diff_date.days),
                    )
                    if diff_date.days >= 0:
                        self._state = diff_date.days
                        self._days = diff_date.days
                    else:
                        self._state = None
                    self._message = next_collection["message"]
                    break
        self.async_write_ha_state()
def _handle_coordinator_update ( self ) -> None : _LOGGER . debug ( "I am %s, callback function called" , self . _attr_unique_id , ) if self . _trash_type_id == "A2954658" or self . _trash_type_id == "43806A8A" : _LOGGER . debug ( "Container oder Weihnachten!" ) return if self . _trash_type_id == "3F14EDC7" : _LOGGER . debug ( "GELBE TONNE!" ) if ( self . coordinator . data is not None ) and ( self . _street_id in self . coordinator . data ) : street_json = self . coordinator . data [ self . _street_id ] for next_collection in street_json : if self . _trash_type_id == next_collection [ "trashType" ] : ldate = next_collection [ "formattedDate" ] . split ( "." , 3 ) next_date = date ( int ( ldate [ 2 ] ) , int ( ldate [ 1 ] ) , int ( ldate [ 0 ] ) ) _LOGGER . debug ( "Next date %s" , next_date ) _LOGGER . debug ( "Today  %s" , datetime . today ( ) ) _LOGGER . debug ( "Ignore until  %s" , self . _ignore ) if ( self . _ignore is not None ) and ( next_date <= self . _ignore ) : _LOGGER . debug ( "SKIPPING" ) continue diff_date = next_date - date . today ( ) _LOGGER . debug ( "Diff  %s" , diff_date ) self . _next_date = ( datetime ( next_date . year , next_date . month , next_date . day ) . astimezone ( ) . isoformat ( ) ) _LOGGER . debug ( "Updateing native value: %s" , str ( diff_date . days ) , ) if diff_date . days >= 0 : self . _state = diff_date . days self . _days = diff_date . days else : self . _state = None self . _message = next_collection [ "message" ] break self . async_write_ha_state ( )
Handle updated data from the coordinator.
Handle updated data from the coordinator .
"""Handle updated data from the coordinator.""" # Now find my JSON # sub_list_data: lists # the data is structured as a dict. The key is the street_id. # That data to that key is the JSON-dict. # iterate throught the JSON of our street_id! # now find the resulting trash type # next collection date for the trashtype found # the format is dd.mm.yyyy # if the diff date == 0, then it is/was today.
self