Repository: home-assistant/core
File: homeassistant/components/tractive/__init__.py (Python)

Code before:
        for switch, key in SWITCH_KEY_MAP.items():
            if switch_data := event.get(key):
                payload[switch] = switch_data["active"]
        payload[ATTR_POWER_SAVING] = event.get("tracker_state_reason") == "POWER_SAVING"
        self._dispatch_tracker_event(
            TRACKER_SWITCH_STATUS_UPDATED, event["tracker_id"], payload
        )

    def send_health_overview_update(self, event: dict[str, Any]) -> None:
        """Handle health_overview events from Tractive API."""
        # The health_overview response can be at root level or wrapped in 'content'
        # Handle both structures for compatibility
        data = event.get("content", event)

        activity = data.get("activity", {})
        sleep = data.get("sleep")

        sleep_day = None
        sleep_night = None
        minutes_rest = None

        if isinstance(sleep, dict):
            sleep_day = sleep.get("minutesDaySleep")
            sleep_night = sleep.get("minutesNightSleep")
            # Calm minutes can be used as rest indicator
            minutes_rest = sleep.get("minutesCalm")

        payload = {
            ATTR_DAILY_GOAL: activity.get("minutesGoal"),
            ATTR_MINUTES_ACTIVE: activity.get("minutesActive"),
            ATTR_MINUTES_DAY_SLEEP: sleep_day,
            ATTR_MINUTES_NIGHT_SLEEP: sleep_night,
            ATTR_MINUTES_REST: minutes_rest,
        }
        self._dispatch_tracker_event(
            TRACKER_WELLNESS_STATUS_UPDATED, data.get("petId"), payload
        )

    def _send_position_update(self, event: dict[str, Any]) -> None:
        payload = {
            "latitude": event["position"]["latlong"][0],
            "longitude": event["position"]["latlong"][1],
            "accuracy": event["position"]["accuracy"],
            "sensor_used": event["position"]["sensor_used"],
        }
        self._dispatch_tracker_event(
            TRACKER_POSITION_UPDATED, event["tracker_id"], payload
        )

    def _dispatch_tracker_event(
        self, event_name: str, tracker_id: str, payload: dict[str, Any]

Review comment (suggestion):
```suggestion
        sleep_day = sleep.get("minutesDaySleep")
        sleep_night = sleep.get("minutesNightSleep")
        # Calm minutes can be used as rest indicator
        minutes_rest = sleep.get("minutesCalm")
```

Code after:
    def _send_switch_update(self, event: dict[str, Any]) -> None:
        # Sometimes the event contains data for all switches, sometimes only for one.
        payload = {}
        for switch, key in SWITCH_KEY_MAP.items():
            if switch_data := event.get(key):
                payload[switch] = switch_data["active"]
        payload[ATTR_POWER_SAVING] = event.get("tracker_state_reason") == "POWER_SAVING"
        self._dispatch_tracker_event(
            TRACKER_SWITCH_STATUS_UPDATED, event["tracker_id"], payload
        )

    def _send_wellness_update(self, event: dict[str, Any]) -> None:
        sleep_day = None
        sleep_night = None
        if isinstance(event["sleep"], dict):
            sleep_day = event["sleep"]["minutes_day_sleep"]
            sleep_night = event["sleep"]["minutes_night_sleep"]
        payload = {
            ATTR_ACTIVITY_LABEL: event["wellness"].get("activity_label"),
            ATTR_CALORIES: event["activity"]["calories"],
            ATTR_DAILY_GOAL: event["activity"]["minutes_goal"],
            ATTR_MINUTES_ACTIVE: event["activity"]["minutes_active"],
            ATTR_MINUTES_DAY_SLEEP: sleep_day,
            ATTR_MINUTES_NIGHT_SLEEP: sleep_night,
            ATTR_MINUTES_REST: event["activity"]["minutes_rest"],
            ATTR_SLEEP_LABEL: event["wellness"].get("sleep_label"),
        }
        self._dispatch_tracker_event(
            TRACKER_WELLNESS_STATUS_UPDATED, event["pet_id"], payload
        )

    def send_health_overview_update(self, event: dict[str, Any]) -> None:
        """Handle health_overview events from Tractive API."""
        # The health_overview response can be at root level or wrapped in 'content'
        # Handle both structures for compatibility
        data = event.get("content", event)

        activity = data.get("activity", {})
        sleep = data.get("sleep", {})

        payload = {
            ATTR_DAILY_GOAL: activity.get("minutesGoal"),
            ATTR_MINUTES_ACTIVE: activity.get("minutesActive"),
            ATTR_MINUTES_DAY_SLEEP: sleep.get("minutesDaySleep"),
            ATTR_MINUTES_NIGHT_SLEEP: sleep.get("minutesNightSleep"),
            # Calm minutes can be used as rest indicator
            ATTR_MINUTES_REST: sleep.get("minutesCalm"),
        }
        self._dispatch_tracker_event(
            TRACKER_HEALTH_OVERVIEW_UPDATED, data["petId"], payload
        )