mirror of
https://github.com/cyberjunky/home-assistant-garmin_connect.git
synced 2026-01-09 12:57:58 -05:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5155e90c8a | ||
|
|
1844b50877 | ||
|
|
0241207443 | ||
|
|
eaec42124b | ||
|
|
8dea9bfa4b | ||
|
|
f13f59ae46 | ||
|
|
e958d2af89 | ||
|
|
8beb401e41 | ||
|
|
4cd2826643 | ||
|
|
6a5a7fbd34 | ||
|
|
30fe26751c | ||
|
|
05adddd8e5 | ||
|
|
3fd9388170 | ||
|
|
dd7cfc021f | ||
|
|
154190f9e9 | ||
|
|
e2d3a61c0e | ||
|
|
47717f019c | ||
|
|
03f576207f | ||
|
|
db334c0761 | ||
|
|
7ce7bd2277 |
@@ -1,8 +1,10 @@
|
||||
[](https://github.com/custom-components/hacs) [](https://www.python.org/) [](https://www.paypal.me/cyberjunkynl/)
|
||||
[](https://github.com/hacs/integration) [](https://www.python.org/) [](https://www.paypal.me/cyberjunkynl/)
|
||||
|
||||
# Garmin Connect
|
||||
The Garmin Connect integration allows you to expose data from Garmin Connect to Home Assistant.
|
||||
|
||||
NOTE: This integration doesn't support 2FA on Garmin Connect, so if you have enabled it -and want to keep it- this integration doesn't work, it will try to login repeatedly and generate lots of 2FA codes via email.
|
||||
The change of adding support for it is unlikely since the Garmin Connect API is closed source, and will not be open for open-sourced projects.
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from datetime import date
|
||||
import logging
|
||||
|
||||
from garminconnect_ha import (
|
||||
from garminconnect import (
|
||||
Garmin,
|
||||
GarminConnectAuthenticationError,
|
||||
GarminConnectConnectionError,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Config flow for Garmin Connect integration."""
|
||||
import logging
|
||||
|
||||
from garminconnect_ha import (
|
||||
from garminconnect import (
|
||||
Garmin,
|
||||
GarminConnectAuthenticationError,
|
||||
GarminConnectConnectionError,
|
||||
|
||||
@@ -11,7 +11,6 @@ from homeassistant.const import (
|
||||
)
|
||||
|
||||
DOMAIN = "garmin_connect"
|
||||
ATTRIBUTION = "connect.garmin.com"
|
||||
DATA_COORDINATOR = "coordinator"
|
||||
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=5)
|
||||
|
||||
@@ -37,7 +36,7 @@ GARMIN_ENTITY_LIST = {
|
||||
None,
|
||||
False,
|
||||
],
|
||||
"netCalorieGoal": ["Net Calorie Goal", "cal", "mdi:food", None, False],
|
||||
"netCalorieGoal": ["Net Calorie Goal", "kcal", "mdi:food", None, False],
|
||||
"totalDistanceMeters": [
|
||||
"Total Distance Mtr",
|
||||
LENGTH_METERS,
|
||||
@@ -348,10 +347,10 @@ GARMIN_ENTITY_LIST = {
|
||||
"bmi": ["BMI", "bmi", "mdi:food", None, False],
|
||||
"bodyFat": ["Body Fat", PERCENTAGE, "mdi:food", None, False],
|
||||
"bodyWater": ["Body Water", PERCENTAGE, "mdi:water-percent", None, False],
|
||||
"bodyMass": ["Body Mass", MASS_KILOGRAMS, "mdi:food", None, False],
|
||||
"boneMass": ["Bone Mass", MASS_KILOGRAMS, "mdi:bone", None, False],
|
||||
"muscleMass": ["Muscle Mass", MASS_KILOGRAMS, "mdi:dumbbell", None, False],
|
||||
"physiqueRating": ["Physique Rating", None, "mdi:numeric", None, False],
|
||||
"visceralFat": ["Visceral Fat", PERCENTAGE, "mdi:food", None, False],
|
||||
"metabolicAge": ["Metabolic Age", TIME_YEARS, "mdi:calendar-heart", None, False],
|
||||
"nextAlarm": ["Next Alarm Time", None, "mdi:alarm", DEVICE_CLASS_TIMESTAMP, True],
|
||||
"nextAlarm": ["Next Alarm Time", None, "mdi:alarm", None, True],
|
||||
}
|
||||
|
||||
@@ -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_ha==0.1.15"],
|
||||
"requirements": ["garminconnect==0.1.24"],
|
||||
"codeowners": ["@cyberjunky"],
|
||||
"config_flow": true,
|
||||
"iot_class": "cloud_polling",
|
||||
"version": "0.1.3"
|
||||
"version": "0.1.8"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.components.sensor import SensorEntity, SensorStateClass
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ID, DEVICE_CLASS_TIMESTAMP
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -15,7 +15,6 @@ from homeassistant.helpers.update_coordinator import (
|
||||
|
||||
from .alarm_util import calculate_next_active_alarms
|
||||
from .const import (
|
||||
ATTRIBUTION,
|
||||
DATA_COORDINATOR,
|
||||
DOMAIN as GARMIN_DOMAIN,
|
||||
GARMIN_ENTITY_LIST,
|
||||
@@ -83,24 +82,18 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
|
||||
self._unique_id = unique_id
|
||||
self._type = sensor_type
|
||||
self._name = name
|
||||
self._unit = unit
|
||||
self._icon = icon
|
||||
self._device_class = device_class
|
||||
self._enabled_default = enabled_default
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
self._attr_name = name
|
||||
self._attr_device_class = self._device_class
|
||||
self._attr_icon = icon
|
||||
self._attr_native_unit_of_measurement = unit
|
||||
self._attr_unique_id = f"{self._unique_id}_{self._type}"
|
||||
self._attr_state_class = SensorStateClass.TOTAL
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if not self.coordinator.data or not self.coordinator.data[self._type]:
|
||||
return None
|
||||
@@ -115,25 +108,15 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
self.coordinator.data[self._type]
|
||||
)
|
||||
if active_alarms:
|
||||
value = active_alarms[0]
|
||||
return active_alarms[0]
|
||||
else:
|
||||
value = None
|
||||
return None
|
||||
|
||||
if self._device_class == DEVICE_CLASS_TIMESTAMP:
|
||||
return value
|
||||
|
||||
return round(value, 2)
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique ID for this sensor."""
|
||||
return f"{self._unique_id}_{self._type}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return attributes for sensor."""
|
||||
@@ -141,9 +124,7 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
return {}
|
||||
|
||||
attributes = {
|
||||
"source": self.coordinator.data["source"],
|
||||
"last_synced": self.coordinator.data["lastSyncTimestampGMT"],
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
if self._type == "nextAlarm":
|
||||
attributes["next_alarms"] = calculate_next_active_alarms(
|
||||
@@ -174,8 +155,3 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
and self.coordinator.data
|
||||
and self._type in self.coordinator.data
|
||||
)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return self._device_class
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"username": "[%key:common::config_flow::data::username%]"
|
||||
},
|
||||
"description": "Enter your credentials.",
|
||||
"title": "Garmin Connect"
|
||||
"description": "Enter your credentials."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
"password": "Password",
|
||||
"username": "Username"
|
||||
},
|
||||
"description": "Enter your credentials.",
|
||||
"title": "Garmin Connect"
|
||||
"description": "Enter your credentials."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user