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

Code before:
            ATTR_POWER_SAVING: event.get("tracker_state_reason") == "POWER_SAVING",
            ATTR_BATTERY_CHARGING: event["charging_state"] == "CHARGING",
        }
        self._dispatch_tracker_event(
            TRACKER_HARDWARE_STATUS_UPDATED, event["tracker_id"], payload
        )

    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_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],

Review comment (suggestion):
```suggestion
        sleep = data.get("sleep", {})
```

Code after:
        payload = {
            ATTR_BATTERY_LEVEL: event["hardware"]["battery_level"],
            ATTR_TRACKER_STATE: event["tracker_state"].lower(),
            ATTR_POWER_SAVING: event.get("tracker_state_reason") == "POWER_SAVING",
            ATTR_BATTERY_CHARGING: event["charging_state"] == "CHARGING",
        }
        self._dispatch_tracker_event(
            TRACKER_HARDWARE_STATUS_UPDATED, event["tracker_id"], payload
        )

    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 = {