Add Body Composition data to Garmin Connect (#32841)
* Added support for Garmin index smart scale * Added body composition data * Added keyerror exception * Code optimization * Update library, changed logger errors to exception * Fixed manifest
This commit is contained in:
parent
fb22f6c301
commit
109f083c5d
6 changed files with 32 additions and 13 deletions
|
@ -43,13 +43,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
GarminConnectAuthenticationError,
|
||||
GarminConnectTooManyRequestsError,
|
||||
) as err:
|
||||
_LOGGER.error("Error occurred during Garmin Connect login: %s", err)
|
||||
_LOGGER.error("Error occurred during Garmin Connect login request: %s", err)
|
||||
return False
|
||||
except (GarminConnectConnectionError) as err:
|
||||
_LOGGER.error("Error occurred during Garmin Connect login: %s", err)
|
||||
_LOGGER.error(
|
||||
"Connection error occurred during Garmin Connect login request: %s", err
|
||||
)
|
||||
raise ConfigEntryNotReady
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.error("Unknown error occurred during Garmin Connect login")
|
||||
_LOGGER.exception("Unknown error occurred during Garmin Connect login request")
|
||||
return False
|
||||
|
||||
garmin_data = GarminConnectData(hass, garmin_client)
|
||||
|
@ -93,16 +95,18 @@ class GarminConnectData:
|
|||
today = date.today()
|
||||
|
||||
try:
|
||||
self.data = self.client.get_stats(today.isoformat())
|
||||
self.data = self.client.get_stats_and_body(today.isoformat())
|
||||
except (
|
||||
GarminConnectAuthenticationError,
|
||||
GarminConnectTooManyRequestsError,
|
||||
GarminConnectConnectionError,
|
||||
) as err:
|
||||
_LOGGER.error("Error occurred during Garmin Connect get stats: %s", err)
|
||||
return
|
||||
except (GarminConnectConnectionError) as err:
|
||||
_LOGGER.error("Error occurred during Garmin Connect get stats: %s", err)
|
||||
_LOGGER.error(
|
||||
"Error occurred during Garmin Connect get activity request: %s", err
|
||||
)
|
||||
return
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.error("Unknown error occurred during Garmin Connect get stats")
|
||||
_LOGGER.exception(
|
||||
"Unknown error occurred during Garmin Connect get activity request"
|
||||
)
|
||||
return
|
||||
|
|
|
@ -309,4 +309,13 @@ GARMIN_ENTITY_LIST = {
|
|||
DEVICE_CLASS_TIMESTAMP,
|
||||
False,
|
||||
],
|
||||
"weight": ["Weight", "kg", "mdi:weight-kilogram", None, False],
|
||||
"bmi": ["BMI", "", "mdi:food", None, False],
|
||||
"bodyFat": ["Body Fat", "%", "mdi:food", None, False],
|
||||
"bodyWater": ["Body Water", "%", "mdi:water-percent", None, False],
|
||||
"bodyMass": ["Body Mass", "kg", "mdi:food", None, False],
|
||||
"muscleMass": ["Muscle Mass", "kg", "mdi:dumbbell", None, False],
|
||||
"physiqueRating": ["Physique Rating", "", "mdi:numeric", None, False],
|
||||
"visceralFat": ["Visceral Fat", "", "mdi:food", None, False],
|
||||
"metabolicAge": ["Metabolic Age", "", "mdi:calendar-heart", None, False],
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Garmin Connect",
|
||||
"documentation": "https://www.home-assistant.io/integrations/garmin_connect",
|
||||
"dependencies": [],
|
||||
"requirements": ["garminconnect==0.1.8"],
|
||||
"requirements": ["garminconnect==0.1.10"],
|
||||
"codeowners": ["@cyberjunky"],
|
||||
"config_flow": true
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ async def async_setup_entry(
|
|||
) as err:
|
||||
_LOGGER.error("Error occurred during Garmin Connect Client update: %s", err)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.error("Unknown error occurred during Garmin Connect Client update.")
|
||||
_LOGGER.exception("Unknown error occurred during Garmin Connect Client update.")
|
||||
|
||||
entities = []
|
||||
for (
|
||||
|
@ -172,6 +172,12 @@ class GarminConnectSensor(Entity):
|
|||
|
||||
if "Duration" in self._type or "Seconds" in self._type:
|
||||
self._state = data[self._type] // 60
|
||||
elif "Mass" in self._type or self._type == "weight":
|
||||
self._state = round((data[self._type] / 1000), 2)
|
||||
elif (
|
||||
self._type == "bodyFat" or self._type == "bodyWater" or self._type == "bmi"
|
||||
):
|
||||
self._state = round(data[self._type], 2)
|
||||
else:
|
||||
self._state = data[self._type]
|
||||
|
||||
|
|
|
@ -576,7 +576,7 @@ fritzconnection==1.2.0
|
|||
gTTS-token==1.1.3
|
||||
|
||||
# homeassistant.components.garmin_connect
|
||||
garminconnect==0.1.8
|
||||
garminconnect==0.1.10
|
||||
|
||||
# homeassistant.components.gearbest
|
||||
gearbest_parser==1.0.7
|
||||
|
|
|
@ -214,7 +214,7 @@ foobot_async==0.3.1
|
|||
gTTS-token==1.1.3
|
||||
|
||||
# homeassistant.components.garmin_connect
|
||||
garminconnect==0.1.8
|
||||
garminconnect==0.1.10
|
||||
|
||||
# homeassistant.components.geo_json_events
|
||||
# homeassistant.components.usgs_earthquakes_feed
|
||||
|
|
Loading…
Add table
Reference in a new issue