Skip to content

Commit

Permalink
1.1.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Aohzan committed Mar 2, 2023
1 parent 5637252 commit d4088a5
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.1.0

- fix url callback building
- fix device and state class for entities
- add default icons to entities
- update translations and README

## 1.0.0

- stable release
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This a _custom component_ for [Home Assistant](https://www.home-assistant.io/).
The `polar` integration allows you to get information from [Polar](https://flow.polar.com).

You need to create a Client in [Polar Access Link](https://admin.polaraccesslink.com).
Set `https://your_external_access_to_ha/api/polar_auth` as redirect URL. And get client id and secret.
Set `https://your_external_access_to_ha/api/polar_auth` as redirect URL.

## Installation

Expand All @@ -20,6 +20,12 @@ Copy the `custom_components/polar` folder into the config folder.

To add the Polar integration to your installation, go to Configuration >> Integrations in the UI, click the button with + sign and from the list of integrations select Polar.

### Fields

* `Client ID` and `Client secret`: get credentials grom [Polar Access Link](https://admin.polaraccesslink.com).
* `Scan Interval` interval in minutes between two scan to Polar API (default: `30`)
* `URL`: URL used to access to your Home-Assistant (default: your external or internal URL if configured in HA settings)

## Credits

Thanks to https://github.com/burnnat/ha-polar
1 change: 0 additions & 1 deletion custom_components/polar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Polar from a config entry."""

hass.data.setdefault(DOMAIN, {})

coordinator = PolarCoordinator(hass, entry)
Expand Down
16 changes: 10 additions & 6 deletions custom_components/polar/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def _get_user_data_schema(hass_external_url: str | None) -> vol.Schema:

def _get_callback_url(external_url: str) -> str:
"""Get callback url."""
return f"{external_url.strip('/')}{AUTH_CALLBACK_PATH}"
if not external_url.endswith(AUTH_CALLBACK_PATH):
return f"{external_url.strip('/')}{AUTH_CALLBACK_PATH}"
return external_url


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand All @@ -57,11 +59,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

def __init__(self):
def __init__(self) -> None:
"""Initialize class variables."""
self.data = {}
self.external_data = {}
self.accesslink: AccessLink = None
self.data: dict[str, Any] = {}
self.external_data: dict[str, Any] = {}
self.accesslink: AccessLink

async def async_step_user(
self, user_input: dict[str, Any] | None = None
Expand All @@ -72,7 +74,9 @@ async def async_step_user(

return self.async_show_form(
step_id="user",
data_schema=_get_user_data_schema(self.hass.config.external_url),
data_schema=_get_user_data_schema(
self.hass.config.external_url or self.hass.config.internal_url
),
)

self.data = user_input
Expand Down
2 changes: 1 addition & 1 deletion custom_components/polar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"requirements": [
"isodate==0.6.1"
],
"version": "1.0.0"
"version": "1.1.0"
}
10 changes: 9 additions & 1 deletion custom_components/polar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
Expand Down Expand Up @@ -49,6 +50,8 @@ class PolarEntityDescription(SensorEntityDescription):
name="Weight",
unique_id="weight",
native_unit_of_measurement="kg",
device_class=SensorDeviceClass.WEIGHT,
state_class=SensorStateClass.MEASUREMENT,
),
# daily
PolarEntityDescription(
Expand All @@ -60,19 +63,22 @@ class PolarEntityDescription(SensorEntityDescription):
attributes_keys=[
"active-calories",
],
icon="mdi:walk",
),
PolarEntityDescription(
key_category=ATTR_LAST_DAILY,
key="duration",
name="Daily activity Duration",
unique_id="daily_activity_duration",
icon="mdi:clock-time-three",
),
PolarEntityDescription(
key_category=ATTR_LAST_DAILY,
key="active-steps",
native_unit_of_measurement="steps",
name="Daily activity Steps",
unique_id="daily_activity_steps",
icon="mdi:shoe-print",
),
# exercise
PolarEntityDescription(
Expand All @@ -90,6 +96,7 @@ class PolarEntityDescription(SensorEntityDescription):
"running_index",
"device",
],
icon="mdi:run",
),
# sleep
PolarEntityDescription(
Expand Down Expand Up @@ -118,6 +125,7 @@ class PolarEntityDescription(SensorEntityDescription):
"group_solidity_score",
"group_regeneration_score",
],
icon="mdi:sleep",
),
# recharge
PolarEntityDescription(
Expand All @@ -135,6 +143,7 @@ class PolarEntityDescription(SensorEntityDescription):
"ans_charge",
"ans_charge_status",
],
icon="mdi:bed-clock",
),
)

Expand All @@ -153,7 +162,6 @@ class PolarSensor(CoordinatorEntity[PolarCoordinator], SensorEntity):
entity_description: PolarEntityDescription
_attr_attribution = ATTRIBUTION
_attr_has_entity_name = True
_attr_state_class = SensorStateClass.MEASUREMENT

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/polar/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"client_id": "Client ID",
"client_secret": "Client secret",
"scan_interval": "Scan Interval (minutes)",
"external_url": "External URL for Home-Assistant (used in callback url)"
"external_url": "URL for Home-Assistant (used in callback url)"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions custom_components/polar/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"data": {
"client_id": "Client ID",
"client_secret": "Client secret",
"scan_interval": "Scan Interval (minutes)",
"external_url": "External URL for Home-Assistant (used in callback url)"
"external_url": "URL for Home-Assistant (used in callback url)",
"scan_interval": "Scan Interval (minutes)"
},
"description": "Get your credentials from https://admin.polaraccesslink.com",
"title": "Polar integration"
Expand Down
35 changes: 35 additions & 0 deletions custom_components/polar/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"config": {
"abort": {
"already_configured": "Déjà configuré"
},
"error": {
"cannot_connect": "Impossible de se connecter",
"invalid_auth": "Problème d'authentification",
"unknown": "Erreur inconnue"
},
"step": {
"user": {
"data": {
"client_id": "Client ID",
"client_secret": "Client secret",
"external_url": "URL d'accès à Home-Assistant (utilisé pour l'URL de callback)",
"scan_interval": "Interval entre deux mises à jour (minutes)"
},
"description": "Obtenez vos identifiants depuis https://admin.polaraccesslink.com",
"title": "Intégration Polar"
}
}
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "Interval entre deux mises à jour (minutes)"
},
"description": "Configuration de l'intégration Polar",
"title": "Options Polar"
}
}
}
}

0 comments on commit d4088a5

Please sign in to comment.