From 9bcec557461d0edadd956184521916eceaffcc63 Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 11:03:40 +0200 Subject: [PATCH 01/16] Added mmol support Signed-off-by: Daniel Wind --- homeassistant/components/nightscout/config_flow.py | 2 +- homeassistant/components/nightscout/sensor.py | 14 +++++++++----- homeassistant/components/nightscout/strings.json | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/nightscout/config_flow.py b/homeassistant/components/nightscout/config_flow.py index 0c0e8b296cd00..16c29aca495ff 100644 --- a/homeassistant/components/nightscout/config_flow.py +++ b/homeassistant/components/nightscout/config_flow.py @@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) -DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str}) +DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str, vol.Required('Units'): vol.In(["mmol/l", "mg/dl"])}) async def _validate_input(data: dict[str, Any]) -> dict[str, str]: diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 92291bdc4f995..468b10ecd68bc 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -31,18 +31,18 @@ async def async_setup_entry( ) -> None: """Set up the Glucose Sensor.""" api = hass.data[DOMAIN][entry.entry_id] - async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id)], True) - + units = entry.data.get("Units") + async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id, units)], True) class NightscoutSensor(SensorEntity): """Implementation of a Nightscout sensor.""" - _attr_native_unit_of_measurement = "mg/dL" _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str | None) -> None: + def __init__(self, api: NightscoutAPI, name: str, unique_id: str, units: str | None) -> None: """Initialize the Nightscout sensor.""" self.api = api + self._attr_native_unit_of_measurement = units self._attr_unique_id = unique_id self._attr_name = name self._attr_extra_state_attributes: dict[str, Any] = {} @@ -67,7 +67,11 @@ async def async_update(self) -> None: ATTR_DELTA: value.delta, ATTR_DIRECTION: value.direction, } - self._attr_native_value = value.sgv + """Convert to mmol/l and keep 2 decimals""" + if self._attr_native_unit_of_measurement == 'mmol/l': + self._attr_native_value = '{:.2f}'.format(value.sgv * 0.0555) + else: + self._attr_native_value = value.sgv self._attr_icon = self._parse_icon(value.direction) else: self._attr_available = False diff --git a/homeassistant/components/nightscout/strings.json b/homeassistant/components/nightscout/strings.json index fd1d81e1273f1..b0b2ec33a2742 100644 --- a/homeassistant/components/nightscout/strings.json +++ b/homeassistant/components/nightscout/strings.json @@ -3,10 +3,11 @@ "step": { "user": { "title": "Enter your Nightscout server information.", - "description": "- URL: the address of your nightscout instance. I.e.: https://myhomeassistant.duckdns.org:5423\n- API Key (optional): Only use if your instance is protected (auth_default_roles != readable).", + "description": "- URL: the address of your nightscout instance. I.e.: https://myhomeassistant.duckdns.org:5423\n- API Key (optional): Only use if your instance is protected (auth_default_roles != readable).\n- Units: Select the unit type to display.", "data": { "url": "[%key:common::config_flow::data::url%]", - "api_key": "[%key:common::config_flow::data::api_key%]" + "api_key": "[%key:common::config_flow::data::api_key%]", + "unit_type": "[%key:common::config_flow::data::units%]" } } }, From b4ae54cabe99fadb1b4ed92752ef0a4ba781721e Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 16:33:46 +0200 Subject: [PATCH 02/16] update to const, added default, up dependency --- homeassistant/components/nightscout/config_flow.py | 4 ++-- homeassistant/components/nightscout/manifest.json | 3 ++- homeassistant/components/nightscout/sensor.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/nightscout/config_flow.py b/homeassistant/components/nightscout/config_flow.py index 16c29aca495ff..1cd6809b24e78 100644 --- a/homeassistant/components/nightscout/config_flow.py +++ b/homeassistant/components/nightscout/config_flow.py @@ -8,7 +8,7 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_URL +from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_UNIT_OF_MEASUREMENT from homeassistant.exceptions import HomeAssistantError from .const import DOMAIN @@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) -DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str, vol.Required('Units'): vol.In(["mmol/l", "mg/dl"])}) +DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str, vol.Required(CONF_UNIT_OF_MEASUREMENT, default='mg/dL'): vol.In(["mmol/L", "mg/dL"])}) async def _validate_input(data: dict[str, Any]) -> dict[str, str]: diff --git a/homeassistant/components/nightscout/manifest.json b/homeassistant/components/nightscout/manifest.json index 3551b29ee0b0a..9471c2644cf55 100644 --- a/homeassistant/components/nightscout/manifest.json +++ b/homeassistant/components/nightscout/manifest.json @@ -7,5 +7,6 @@ "iot_class": "cloud_polling", "loggers": ["py_nightscout"], "quality_scale": "platinum", - "requirements": ["py-nightscout==1.2.2"] + "requirements": ["py-nightscout==1.3.3"], + "version": "1.0.0" } diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 468b10ecd68bc..4d4b4a5077262 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -31,7 +31,7 @@ async def async_setup_entry( ) -> None: """Set up the Glucose Sensor.""" api = hass.data[DOMAIN][entry.entry_id] - units = entry.data.get("Units") + units = entry.data.get('unit_of_measurement') async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id, units)], True) class NightscoutSensor(SensorEntity): @@ -67,9 +67,9 @@ async def async_update(self) -> None: ATTR_DELTA: value.delta, ATTR_DIRECTION: value.direction, } - """Convert to mmol/l and keep 2 decimals""" - if self._attr_native_unit_of_measurement == 'mmol/l': - self._attr_native_value = '{:.2f}'.format(value.sgv * 0.0555) + if self._attr_native_unit_of_measurement == 'mmol/L': + # self._attr_native_value = value.sgv_mmol <- this does not work with the current 1.3.3 version of the api https://github.com/marciogranzotto/py-nightscout/blob/v1.3.3/py_nightscout/models.py#L82 + self._attr_native_value = round(value.sgv * 0.0555, 1) else: self._attr_native_value = value.sgv self._attr_icon = self._parse_icon(value.direction) From 29c28068090927eb7f3ebd852ea66e8630c95460 Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 17:04:10 +0200 Subject: [PATCH 03/16] back to 1.2.2, bad testing --- homeassistant/components/nightscout/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/manifest.json b/homeassistant/components/nightscout/manifest.json index 9471c2644cf55..95546a2f3caad 100644 --- a/homeassistant/components/nightscout/manifest.json +++ b/homeassistant/components/nightscout/manifest.json @@ -7,6 +7,6 @@ "iot_class": "cloud_polling", "loggers": ["py_nightscout"], "quality_scale": "platinum", - "requirements": ["py-nightscout==1.3.3"], + "requirements": ["py-nightscout==1.2.2"], "version": "1.0.0" } From 6ab99a988ac49d4b54f9ca17fb42a0e002d9a238 Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 17:48:00 +0200 Subject: [PATCH 04/16] changes to constant and unit --- homeassistant/components/nightscout/config_flow.py | 11 ++++++++--- homeassistant/components/nightscout/const.py | 2 ++ homeassistant/components/nightscout/sensor.py | 14 +++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/nightscout/config_flow.py b/homeassistant/components/nightscout/config_flow.py index 1cd6809b24e78..3dbac0d429de9 100644 --- a/homeassistant/components/nightscout/config_flow.py +++ b/homeassistant/components/nightscout/config_flow.py @@ -11,13 +11,18 @@ from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_UNIT_OF_MEASUREMENT from homeassistant.exceptions import HomeAssistantError -from .const import DOMAIN +from .const import DOMAIN, MG_DL, MMOL_L from .utils import hash_from_url _LOGGER = logging.getLogger(__name__) -DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str, vol.Required(CONF_UNIT_OF_MEASUREMENT, default='mg/dL'): vol.In(["mmol/L", "mg/dL"])}) - +DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_URL): str, + vol.Optional(CONF_API_KEY): str, + vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=MG_DL): vol.In([MG_DL, MMOL_L]), + } +) async def _validate_input(data: dict[str, Any]) -> dict[str, str]: """Validate the user input allows us to connect.""" diff --git a/homeassistant/components/nightscout/const.py b/homeassistant/components/nightscout/const.py index 7e47f7ff49d4a..182164d8a849e 100644 --- a/homeassistant/components/nightscout/const.py +++ b/homeassistant/components/nightscout/const.py @@ -5,3 +5,5 @@ ATTR_DEVICE = "device" ATTR_DELTA = "delta" ATTR_DIRECTION = "direction" +MMOL_L = "mmol/L" +MG_DL = "mg/dL" \ No newline at end of file diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 4d4b4a5077262..1005e7cce6c80 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -11,11 +11,11 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_DATE +from homeassistant.const import ATTR_DATE, CONF_UNIT_OF_MEASUREMENT from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import ATTR_DELTA, ATTR_DEVICE, ATTR_DIRECTION, DOMAIN +from .const import ATTR_DELTA, ATTR_DEVICE, ATTR_DIRECTION, DOMAIN, MMOL_L SCAN_INTERVAL = timedelta(minutes=1) @@ -31,18 +31,18 @@ async def async_setup_entry( ) -> None: """Set up the Glucose Sensor.""" api = hass.data[DOMAIN][entry.entry_id] - units = entry.data.get('unit_of_measurement') - async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id, units)], True) + unit = entry.data[CONF_UNIT_OF_MEASUREMENT] + async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id, unit)], True) class NightscoutSensor(SensorEntity): """Implementation of a Nightscout sensor.""" _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str, units: str | None) -> None: + def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str | None) -> None: """Initialize the Nightscout sensor.""" self.api = api - self._attr_native_unit_of_measurement = units + self._attr_native_unit_of_measurement = unit self._attr_unique_id = unique_id self._attr_name = name self._attr_extra_state_attributes: dict[str, Any] = {} @@ -67,7 +67,7 @@ async def async_update(self) -> None: ATTR_DELTA: value.delta, ATTR_DIRECTION: value.direction, } - if self._attr_native_unit_of_measurement == 'mmol/L': + if self._attr_native_unit_of_measurement == MMOL_L: # self._attr_native_value = value.sgv_mmol <- this does not work with the current 1.3.3 version of the api https://github.com/marciogranzotto/py-nightscout/blob/v1.3.3/py_nightscout/models.py#L82 self._attr_native_value = round(value.sgv * 0.0555, 1) else: From 33ce002d9052e98fa512e8a45124c81f3399dc4b Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 18:16:59 +0200 Subject: [PATCH 05/16] fixes for tests --- homeassistant/components/nightscout/const.py | 2 +- homeassistant/components/nightscout/manifest.json | 3 +-- homeassistant/components/nightscout/sensor.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/nightscout/const.py b/homeassistant/components/nightscout/const.py index 182164d8a849e..1c173842402fc 100644 --- a/homeassistant/components/nightscout/const.py +++ b/homeassistant/components/nightscout/const.py @@ -6,4 +6,4 @@ ATTR_DELTA = "delta" ATTR_DIRECTION = "direction" MMOL_L = "mmol/L" -MG_DL = "mg/dL" \ No newline at end of file +MG_DL = "mg/dL" diff --git a/homeassistant/components/nightscout/manifest.json b/homeassistant/components/nightscout/manifest.json index 95546a2f3caad..3551b29ee0b0a 100644 --- a/homeassistant/components/nightscout/manifest.json +++ b/homeassistant/components/nightscout/manifest.json @@ -7,6 +7,5 @@ "iot_class": "cloud_polling", "loggers": ["py_nightscout"], "quality_scale": "platinum", - "requirements": ["py-nightscout==1.2.2"], - "version": "1.0.0" + "requirements": ["py-nightscout==1.2.2"] } diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 1005e7cce6c80..3f81af7afd4de 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -39,7 +39,7 @@ class NightscoutSensor(SensorEntity): _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str | None) -> None: + def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str) -> None: """Initialize the Nightscout sensor.""" self.api = api self._attr_native_unit_of_measurement = unit From 8be1303fd1623f3a2aa69027bda700b3f95d46f2 Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 18:21:09 +0200 Subject: [PATCH 06/16] Manifest does need version --- homeassistant/components/nightscout/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/manifest.json b/homeassistant/components/nightscout/manifest.json index 3551b29ee0b0a..43a437175824b 100644 --- a/homeassistant/components/nightscout/manifest.json +++ b/homeassistant/components/nightscout/manifest.json @@ -7,5 +7,6 @@ "iot_class": "cloud_polling", "loggers": ["py_nightscout"], "quality_scale": "platinum", - "requirements": ["py-nightscout==1.2.2"] + "requirements": ["py-nightscout==1.2.2"], + "version": "1.0.1" } From fd13d52dc9b5342ff4d79d84e84a64c02a4b1601 Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 18:26:34 +0200 Subject: [PATCH 07/16] Remove verion for core, update strings --- homeassistant/components/nightscout/manifest.json | 3 +-- homeassistant/components/nightscout/sensor.py | 2 +- homeassistant/components/nightscout/strings.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/nightscout/manifest.json b/homeassistant/components/nightscout/manifest.json index 43a437175824b..3551b29ee0b0a 100644 --- a/homeassistant/components/nightscout/manifest.json +++ b/homeassistant/components/nightscout/manifest.json @@ -7,6 +7,5 @@ "iot_class": "cloud_polling", "loggers": ["py_nightscout"], "quality_scale": "platinum", - "requirements": ["py-nightscout==1.2.2"], - "version": "1.0.1" + "requirements": ["py-nightscout==1.2.2"] } diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 3f81af7afd4de..1005e7cce6c80 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -39,7 +39,7 @@ class NightscoutSensor(SensorEntity): _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str) -> None: + def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str | None) -> None: """Initialize the Nightscout sensor.""" self.api = api self._attr_native_unit_of_measurement = unit diff --git a/homeassistant/components/nightscout/strings.json b/homeassistant/components/nightscout/strings.json index b0b2ec33a2742..7cfc40ab3cb57 100644 --- a/homeassistant/components/nightscout/strings.json +++ b/homeassistant/components/nightscout/strings.json @@ -7,7 +7,7 @@ "data": { "url": "[%key:common::config_flow::data::url%]", "api_key": "[%key:common::config_flow::data::api_key%]", - "unit_type": "[%key:common::config_flow::data::units%]" + "unit_type": "[%key:common::config_flow::data::unit_of_measurement%]" } } }, From 6b0339d3bb5e5f403591985eb0d4191f6961302b Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Tue, 24 Sep 2024 18:54:56 +0200 Subject: [PATCH 08/16] unique_id defaults to None --- homeassistant/components/nightscout/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 1005e7cce6c80..846fa099b14c5 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -39,7 +39,7 @@ class NightscoutSensor(SensorEntity): _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str, unit: str | None) -> None: + def __init__(self, api: NightscoutAPI, name: str, unique_id: str | None, unit: str) -> None: """Initialize the Nightscout sensor.""" self.api = api self._attr_native_unit_of_measurement = unit From 62ad444d3c8628506648ef42985c191638ec9501 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 08:38:49 +0200 Subject: [PATCH 09/16] change key name Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/strings.json b/homeassistant/components/nightscout/strings.json index 7cfc40ab3cb57..064d2802e2bcd 100644 --- a/homeassistant/components/nightscout/strings.json +++ b/homeassistant/components/nightscout/strings.json @@ -7,7 +7,7 @@ "data": { "url": "[%key:common::config_flow::data::url%]", "api_key": "[%key:common::config_flow::data::api_key%]", - "unit_type": "[%key:common::config_flow::data::unit_of_measurement%]" + "unit_of_measurement": "[%key:common::config_flow::data::unit_of_measurement%]" } } }, From 5e59f2a70c1559a88426d9ef934589e7cf7b186e Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 08:39:07 +0200 Subject: [PATCH 10/16] change order Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/config_flow.py b/homeassistant/components/nightscout/config_flow.py index 3dbac0d429de9..900b60f86d571 100644 --- a/homeassistant/components/nightscout/config_flow.py +++ b/homeassistant/components/nightscout/config_flow.py @@ -8,7 +8,7 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_UNIT_OF_MEASUREMENT +from homeassistant.const import CONF_API_KEY, CONF_UNIT_OF_MEASUREMENT, CONF_URL from homeassistant.exceptions import HomeAssistantError from .const import DOMAIN, MG_DL, MMOL_L From 605da8edc1a05687040fb4ea2aa0c74fd8cd6f52 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 08:39:47 +0200 Subject: [PATCH 11/16] Better readability Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/sensor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 846fa099b14c5..1ab527b733779 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -32,7 +32,9 @@ async def async_setup_entry( """Set up the Glucose Sensor.""" api = hass.data[DOMAIN][entry.entry_id] unit = entry.data[CONF_UNIT_OF_MEASUREMENT] - async_add_entities([NightscoutSensor(api, "Blood Sugar", entry.unique_id, unit)], True) + async_add_entities( + [NightscoutSensor(api, "Blood Sugar", entry.unique_id, unit)], True + ) class NightscoutSensor(SensorEntity): """Implementation of a Nightscout sensor.""" From 812409b4568d7b18d9c029d490402bb7f73f1e43 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 08:40:09 +0200 Subject: [PATCH 12/16] Better readability Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/sensor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 1ab527b733779..8dacf6389d97d 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -41,7 +41,9 @@ class NightscoutSensor(SensorEntity): _attr_icon = "mdi:cloud-question" - def __init__(self, api: NightscoutAPI, name: str, unique_id: str | None, unit: str) -> None: + def __init__( + self, api: NightscoutAPI, name: str, unique_id: str | None, unit: str + ) -> None: """Initialize the Nightscout sensor.""" self.api = api self._attr_native_unit_of_measurement = unit From cf995e14f8243f43626415de1974112df7fdbe46 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 14:57:49 +0200 Subject: [PATCH 13/16] Remove comment Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/sensor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 8dacf6389d97d..604e21d0f30b9 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -72,7 +72,6 @@ async def async_update(self) -> None: ATTR_DIRECTION: value.direction, } if self._attr_native_unit_of_measurement == MMOL_L: - # self._attr_native_value = value.sgv_mmol <- this does not work with the current 1.3.3 version of the api https://github.com/marciogranzotto/py-nightscout/blob/v1.3.3/py_nightscout/models.py#L82 self._attr_native_value = round(value.sgv * 0.0555, 1) else: self._attr_native_value = value.sgv From 1b0db60b93a75b68e3e07ef393d1a72ab54631f9 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 15:03:56 +0200 Subject: [PATCH 14/16] Added a white line before class Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/nightscout/sensor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 604e21d0f30b9..ef3a85130b1b9 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -36,6 +36,7 @@ async def async_setup_entry( [NightscoutSensor(api, "Blood Sugar", entry.unique_id, unit)], True ) + class NightscoutSensor(SensorEntity): """Implementation of a Nightscout sensor.""" From a6c03158b552d7040aa2b51e7d68cf82dcd67b85 Mon Sep 17 00:00:00 2001 From: danielwindit Date: Wed, 25 Sep 2024 15:18:52 +0200 Subject: [PATCH 15/16] Make MG_DL more default Co-authored-by: Joost Lekkerkerker --- homeassistant/components/nightscout/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index ef3a85130b1b9..044afb134c0ed 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -31,7 +31,7 @@ async def async_setup_entry( ) -> None: """Set up the Glucose Sensor.""" api = hass.data[DOMAIN][entry.entry_id] - unit = entry.data[CONF_UNIT_OF_MEASUREMENT] + unit = entry.data.get(CONF_UNIT_OF_MEASUREMENT, MG_DL) async_add_entities( [NightscoutSensor(api, "Blood Sugar", entry.unique_id, unit)], True ) From 40393b396206972591c4861f06cb7aab2d4a522f Mon Sep 17 00:00:00 2001 From: Daniel Wind Date: Wed, 25 Sep 2024 15:20:19 +0200 Subject: [PATCH 16/16] MG_DL must be defined --- homeassistant/components/nightscout/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 044afb134c0ed..1338219b48c01 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -15,7 +15,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import ATTR_DELTA, ATTR_DEVICE, ATTR_DIRECTION, DOMAIN, MMOL_L +from .const import ATTR_DELTA, ATTR_DEVICE, ATTR_DIRECTION, DOMAIN, MMOL_L, MG_DL SCAN_INTERVAL = timedelta(minutes=1)