Adapt Tractive integration the latest API changes (#114380)

Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
Maciej Bieniek 2024-03-28 13:25:01 +01:00 committed by GitHub
parent 5b98a8458f
commit c9c0625fa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 17 deletions

View File

@ -40,7 +40,6 @@ from .const import (
SERVER_UNAVAILABLE,
SWITCH_KEY_MAP,
TRACKABLES,
TRACKER_ACTIVITY_STATUS_UPDATED,
TRACKER_HARDWARE_STATUS_UPDATED,
TRACKER_POSITION_UPDATED,
TRACKER_SWITCH_STATUS_UPDATED,
@ -220,9 +219,6 @@ class TractiveClient:
if server_was_unavailable:
_LOGGER.debug("Tractive is back online")
server_was_unavailable = False
if event["message"] == "activity_update":
self._send_activity_update(event)
continue
if event["message"] == "wellness_overview":
self._send_wellness_update(event)
continue
@ -291,15 +287,6 @@ class TractiveClient:
TRACKER_SWITCH_STATUS_UPDATED, event["tracker_id"], payload
)
def _send_activity_update(self, event: dict[str, Any]) -> None:
payload = {
ATTR_MINUTES_ACTIVE: event["progress"]["achieved_minutes"],
ATTR_DAILY_GOAL: event["progress"]["goal_minutes"],
}
self._dispatch_tracker_event(
TRACKER_ACTIVITY_STATUS_UPDATED, event["pet_id"], payload
)
def _send_wellness_update(self, event: dict[str, Any]) -> None:
sleep_day = None
sleep_night = None
@ -309,6 +296,8 @@ class TractiveClient:
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"],

View File

@ -26,7 +26,6 @@ CLIENT_ID = "625e5349c3c3b41c28a669f1"
CLIENT = "client"
TRACKABLES = "trackables"
TRACKER_ACTIVITY_STATUS_UPDATED = f"{DOMAIN}_tracker_activity_updated"
TRACKER_HARDWARE_STATUS_UPDATED = f"{DOMAIN}_tracker_hardware_status_updated"
TRACKER_POSITION_UPDATED = f"{DOMAIN}_tracker_position_updated"
TRACKER_SWITCH_STATUS_UPDATED = f"{DOMAIN}_tracker_switch_updated"

View File

@ -37,7 +37,6 @@ from .const import (
CLIENT,
DOMAIN,
TRACKABLES,
TRACKER_ACTIVITY_STATUS_UPDATED,
TRACKER_HARDWARE_STATUS_UPDATED,
TRACKER_WELLNESS_STATUS_UPDATED,
)
@ -118,7 +117,7 @@ SENSOR_TYPES: tuple[TractiveSensorEntityDescription, ...] = (
key=ATTR_MINUTES_ACTIVE,
translation_key="activity_time",
native_unit_of_measurement=UnitOfTime.MINUTES,
signal_prefix=TRACKER_ACTIVITY_STATUS_UPDATED,
signal_prefix=TRACKER_WELLNESS_STATUS_UPDATED,
state_class=SensorStateClass.TOTAL,
),
TractiveSensorEntityDescription(
@ -139,7 +138,7 @@ SENSOR_TYPES: tuple[TractiveSensorEntityDescription, ...] = (
key=ATTR_DAILY_GOAL,
translation_key="daily_goal",
native_unit_of_measurement=UnitOfTime.MINUTES,
signal_prefix=TRACKER_ACTIVITY_STATUS_UPDATED,
signal_prefix=TRACKER_WELLNESS_STATUS_UPDATED,
),
TractiveSensorEntityDescription(
key=ATTR_MINUTES_DAY_SLEEP,