Compare commits

...

14 Commits
0.2.1 ... 0.2.6

Author SHA1 Message Date
Ron
d118638429 Corrected units/device type for some body related sensors 2023-01-06 12:50:22 +01:00
Ron
3103929f5f Updated version and bumped garminconnect pkg version 2023-01-06 12:49:27 +01:00
Ron
842355d273 Added debug logging 2023-01-06 12:48:23 +01:00
Ron
e2728b6bc2 Update manifest.json 2023-01-04 20:08:21 +01:00
Ron
b75133a2d4 Fixed error with stress qualfier 2023-01-04 20:08:07 +01:00
Ron
ecbed70aee Update manifest.json 2023-01-04 19:43:06 +01:00
Ron
a761bc00a3 Update sensor.py 2023-01-04 19:42:46 +01:00
Ron
517bd5af5d Converted alarm time value to datetime 2023-01-04 19:42:20 +01:00
Ron
dc4e7301d8 Update manifest.json 2023-01-04 19:04:57 +01:00
Ron
e7ab9ef561 Update sensor.py 2023-01-04 19:04:04 +01:00
Ron
5438cd2d59 Updated version 2023-01-04 15:04:00 +01:00
Ron
4113550397 Implemented SensorDeviceClass 2023-01-04 15:03:23 +01:00
Ron
4b53fdb162 Implemented SensorDeviceClass 2023-01-04 15:02:47 +01:00
Ron Klinkien
6a1b5240d7 Update README.md 2022-05-24 21:19:04 +02:00
5 changed files with 55 additions and 37 deletions

View File

@@ -10,9 +10,10 @@ The change of adding support for it is unlikely since the Garmin Connect API is
### HACS - Recommended
- Have [HACS](https://hacs.xyz) installed, this will allow you to easily manage and track updates.
- Add https://github.com/cyberjunky/home-assistant-garmin_connect to custom repositories in HACS
- Inside HACS click 'Explore & download repositories'
- Search for 'Garmin Connect'.
- Click Install below the found integration.
- Click on found integration.
- Click Download this repository with HACS.
- Restart Home-Assistant.
- Follow configuration steps below.

View File

@@ -93,10 +93,13 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
summary = await self.hass.async_add_executor_job(
self._api.get_user_summary, date.today().isoformat()
)
_LOGGER.debug(summary)
body = await self.hass.async_add_executor_job(
self._api.get_body_composition, date.today().isoformat()
)
_LOGGER.debug(body)
alarms = await self.hass.async_add_executor_job(self._api.get_device_alarms)
_LOGGER.debug(alarms)
except (
GarminConnectAuthenticationError,
GarminConnectTooManyRequestsError,

View File

@@ -2,13 +2,13 @@
from datetime import timedelta
from homeassistant.const import (
DEVICE_CLASS_TIMESTAMP,
LENGTH_METERS,
MASS_KILOGRAMS,
PERCENTAGE,
TIME_MINUTES,
TIME_YEARS,
)
from homeassistant.components.sensor import SensorDeviceClass
DOMAIN = "garmin_connect"
DATA_COORDINATOR = "coordinator"
@@ -41,21 +41,21 @@ GARMIN_ENTITY_LIST = {
"Total Distance Mtr",
LENGTH_METERS,
"mdi:walk",
None,
SensorDeviceClass.DISTANCE,
True,
],
"wellnessStartTimeLocal": [
"Wellness Start Time",
None,
"mdi:clock",
DEVICE_CLASS_TIMESTAMP,
SensorDeviceClass.TIMESTAMP,
False,
],
"wellnessEndTimeLocal": [
"Wellness End Time",
None,
"mdi:clock",
DEVICE_CLASS_TIMESTAMP,
SensorDeviceClass.TIMESTAMP,
False,
],
"wellnessDescription": ["Wellness Description", "", "mdi:clock", None, False],
@@ -63,7 +63,7 @@ GARMIN_ENTITY_LIST = {
"Wellness Distance Mtr",
LENGTH_METERS,
"mdi:walk",
None,
SensorDeviceClass.DISTANCE,
False,
],
"wellnessActiveKilocalories": [
@@ -102,14 +102,14 @@ GARMIN_ENTITY_LIST = {
"Floors Ascended Mtr",
LENGTH_METERS,
"mdi:stairs",
None,
SensorDeviceClass.DISTANCE,
False,
],
"floorsDescendedInMeters": [
"Floors Descended Mtr",
LENGTH_METERS,
"mdi:stairs",
None,
SensorDeviceClass.DISTANCE,
False,
],
"floorsAscended": ["Floors Ascended", "floors", "mdi:stairs", None, True],
@@ -197,49 +197,49 @@ GARMIN_ENTITY_LIST = {
"Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"restStressPercentage": [
"Rest Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"activityStressPercentage": [
"Activity Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"uncategorizedStressPercentage": [
"Uncat. Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"lowStressPercentage": [
"Low Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"mediumStressPercentage": [
"Medium Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"highStressPercentage": [
"High Stress Percentage",
PERCENTAGE,
"mdi:flash-alert",
None,
SensorDeviceClass.BATTERY,
False,
],
"moderateIntensityMinutes": [
@@ -267,35 +267,35 @@ GARMIN_ENTITY_LIST = {
"Body Battery Charged",
PERCENTAGE,
"mdi:battery-charging-100",
None,
SensorDeviceClass.BATTERY,
True,
],
"bodyBatteryDrainedValue": [
"Body Battery Drained",
PERCENTAGE,
"mdi:battery-alert-variant-outline",
None,
SensorDeviceClass.BATTERY,
True,
],
"bodyBatteryHighestValue": [
"Body Battery Highest",
PERCENTAGE,
"mdi:battery-heart",
None,
SensorDeviceClass.BATTERY,
True,
],
"bodyBatteryLowestValue": [
"Body Battery Lowest",
PERCENTAGE,
"mdi:battery-heart-outline",
None,
SensorDeviceClass.BATTERY,
True,
],
"bodyBatteryMostRecentValue": [
"Body Battery Most Recent",
PERCENTAGE,
"mdi:battery-positive",
None,
SensorDeviceClass.BATTERY,
True,
],
"averageSpo2": ["Average SPO2", PERCENTAGE, "mdi:diabetes", None, True],
@@ -305,7 +305,7 @@ GARMIN_ENTITY_LIST = {
"Latest SPO2 Time",
None,
"mdi:diabetes",
DEVICE_CLASS_TIMESTAMP,
SensorDeviceClass.TIMESTAMP,
False,
],
"averageMonitoringEnvironmentAltitude": [
@@ -340,17 +340,17 @@ GARMIN_ENTITY_LIST = {
"Latest Respiration Update",
None,
"mdi:progress-clock",
DEVICE_CLASS_TIMESTAMP,
SensorDeviceClass.TIMESTAMP,
False,
],
"weight": ["Weight", MASS_KILOGRAMS, "mdi:weight-kilogram", None, False],
"weight": ["Weight", MASS_KILOGRAMS, "mdi:weight-kilogram", SensorDeviceClass.WEIGHT, False],
"bmi": ["BMI", "bmi", "mdi:food", None, False],
"bodyFat": ["Body Fat", PERCENTAGE, "mdi:food", None, False],
"bodyWater": ["Body Water", PERCENTAGE, "mdi:water-percent", None, False],
"boneMass": ["Bone Mass", MASS_KILOGRAMS, "mdi:bone", None, False],
"muscleMass": ["Muscle Mass", MASS_KILOGRAMS, "mdi:dumbbell", None, False],
"bodyFat": ["Body Fat", PERCENTAGE, "mdi:food", SensorDeviceClass.BATTERY, False],
"bodyWater": ["Body Water", PERCENTAGE, "mdi:water-percent", SensorDeviceClass.BATTERY, False],
"boneMass": ["Bone Mass", MASS_KILOGRAMS, "mdi:bone", SensorDeviceClass.WEIGHT, False],
"muscleMass": ["Muscle Mass", MASS_KILOGRAMS, "mdi:dumbbell", SensorDeviceClass.WEIGHT, False],
"physiqueRating": ["Physique Rating", None, "mdi:numeric", None, False],
"visceralFat": ["Visceral Fat", PERCENTAGE, "mdi:food", None, False],
"visceralFat": ["Visceral Fat", PERCENTAGE, "mdi:food", SensorDeviceClass.BATTERY, False],
"metabolicAge": ["Metabolic Age", TIME_YEARS, "mdi:calendar-heart", None, False],
"nextAlarm": ["Next Alarm Time", None, "mdi:alarm", None, True],
"nextAlarm": ["Next Alarm Time", None, "mdi:alarm", SensorDeviceClass.TIMESTAMP, True],
}

View File

@@ -3,9 +3,9 @@
"name": "Garmin Connect",
"documentation": "https://github.com/cyberjunky/home-assistant-garmin_connect",
"issue_tracker": "https://github.com/cyberjunky/home-assistant-garmin_connect/issues",
"requirements": ["garminconnect==0.1.24"],
"requirements": ["garminconnect==0.1.50"],
"codeowners": ["@cyberjunky"],
"config_flow": true,
"iot_class": "cloud_polling",
"version": "0.1.8"
"version": "0.2.6"
}

View File

@@ -2,10 +2,16 @@
from __future__ import annotations
import logging
import datetime
import pytz
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.components.sensor import (
SensorEntity,
SensorStateClass,
SensorDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ID, DEVICE_CLASS_TIMESTAMP
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import (
@@ -108,12 +114,20 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
self.coordinator.data[self._type]
)
if active_alarms:
return active_alarms[0]
date_time_obj = datetime.datetime.strptime(active_alarms[0], "%Y-%m-%dT%H:%M:%S")
timezone = pytz.timezone('UTC')
timezone_date_time_obj = timezone.localize(date_time_obj)
return timezone_date_time_obj
else:
return None
elif self._type == "stressQualifier":
return value
if self._device_class == DEVICE_CLASS_TIMESTAMP:
return value
if self._device_class == SensorDeviceClass.TIMESTAMP:
date_time_obj = datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")
timezone = pytz.timezone('UTC')
timezone_date_time_obj = timezone.localize(date_time_obj)
return timezone_date_time_obj
return round(value, 2)