Skip to content

Reward sensor est brisé #827

Closed
Closed

Description

@ic-dev21

Le endpoint sur lequel on se basait n'est maintenant plus feedé en information, on doit maintenant interroger le websocket pour les détails.

Ceci cause donc un reward sensor collé à 0, et certains bugs au niveau de l'attribut next_events du sensor défi.

Il n'y a aucune information de event id dans ces messages ce qui nuit à leur traitement:

2025-12-14 08:43:29.162 DEBUG (MainThread) [pyhilo] [TRACE] Received message on websocket(_parse_message) /ChallengeHub: {'type': 1, 'target': 'ChallengeConsumptionUpdatedValuesReceived', 'arguments': [{'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}]}
2025-12-14 08:43:29.179 DEBUG (MainThread) [custom_components.hilo] Received websocket message type: WebsocketEvent(event_type_id=1, target='ChallengeConsumptionUpdatedValuesReceived', arguments=[{'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}], invocation=None, error=None, timestamp=datetime.datetime(2025, 12, 14, 8, 43, 27, 851063), event_type='INVOKE')
2025-12-14 08:43:29.179 DEBUG (MainThread) [custom_components.hilo] handle_websocket_message_ msg_data WebsocketEvent(event_type_id=1, target='ChallengeConsumptionUpdatedValuesReceived', arguments=[{'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}], invocation=None, error=None, timestamp=datetime.datetime(2025, 12, 14, 8, 43, 27, 851063), event_type='INVOKE')
2025-12-14 08:43:29.180 DEBUG (MainThread) [custom_components.hilo] handle_challenge_details_update challenge is {'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}
2025-12-14 08:43:29.182 DEBUG (MainThread) [custom_components.hilo] UPDATING challenge in reward: {'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}
2025-12-14 08:43:29.182 DEBUG (MainThread) [custom_components.hilo] UPDATING challenge in reward: {'generatedTimeUTC': '2025-12-14T13:43:29.1031398+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}
2025-12-14 08:43:29.184 DEBUG (MainThread) [custom_components.hilo] UPDATING challenge in reward: {'generatedTimeUTC': '2025-12-14T13:43:29.105986+00:00', 'cumulativeBaselinePoints': [{'timeUTC': '2025-12-14T11:00:00+00:00', 'wh': 0.0}, {'timeUTC': '2025-12-14T12:00:00+00:00', 'wh': 10321.510314941406}, {'timeUTC': '2025-12-14T13:00:00+00:00', 'wh': 20671.817779541016}, {'timeUTC': '2025-12-14T14:00:00+00:00', 'wh': 31173.324584960938}, {'timeUTC': '2025-12-14T15:00:00+00:00', 'wh': 41722.83172607422}]}

Activity

  1. ic-dev21 commented on Dec 15, 2025

    @ic-dev21
    CollaboratorAuthor

    async def handle_challenge_details_update(self, challenge):
    """Handle challenge detail updates."""
    LOG.debug("handle_challenge_details_update challenge is %s", challenge)
    challenge = challenge[0] if isinstance(challenge, list) else challenge
    event_id = challenge.get("id")
    event_has_id = event_id is not None
    # In case we get a consumption update (there is no event id),
    # get the event id of the next event so that we can update it
    if event_id is None and len(self._next_events) > 0:
    event_id = self._next_events[0]["event_id"]
    progress = challenge.get("progress", "unknown")
    baseline_points = challenge.get("cumulativeBaselinePoints", [])
    if not baseline_points:
    consumption = challenge.get("consumption", {})
    baseline_points = consumption.get("cumulativeBaselinePoints", [])
    if baseline_points:
    baselinewH = baseline_points[-1]["wh"]
    else:
    baselinewH = challenge.get("baselineWh", 0)
    allowed_kwh = baselinewH / 1000 if baselinewH > 0 else 0
    used_wH = challenge.get("currentWh", 0)
    if used_wH is not None and used_wH > 0:
    used_kWh = used_wH / 1000
    else:
    used_kWh = 0
    LOG.debug("handle_challenge_details_update progress is %s", progress)
    LOG.debug("handle_challenge_details_update baselineWh is %s", baselinewH)
    LOG.debug("handle_challenge_details_update used_kwh is %s", used_kWh)
    LOG.debug("handle_challenge_details_update allowed_kwh is %s", allowed_kwh)
    if event_id in self._events:
    if challenge.get("progress") == "completed":
    # ajout d'un asyncio sleep ici pour avoir l'état completed avant le retrait du challenge
    await asyncio.sleep(300)
    del self._events[event_id]
    # Consumption update
    elif used_wH is not None and used_wH > 0:
    current_event = self._events[event_id]
    current_event.update_wh(used_wH)
    # For non consumption updates, we need an event id
    elif event_has_id:
    current_event = self._events[event_id]
    updated_event = Event(**{**current_event.as_dict(), **challenge})
    if self._hilo.appreciation > 0:
    updated_event.appreciation(self._hilo.appreciation)
    if self._hilo.pre_cold > 0:
    updated_event.pre_cold(self._hilo.pre_cold)
    if baselinewH > 0:
    updated_event.update_allowed_wh(baselinewH)
    self._events[event_id] = updated_event
    self._update_next_events()

  2. ic-dev21 commented on Dec 20, 2025

    @ic-dev21
    CollaboratorAuthor

    Fixed par #825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions