From 95aafd4bfd0be0b957d7c8055c38453c1a25bce4 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 15:45:59 +0000 Subject: [PATCH 1/6] Adding sun_chance field to weather forecasts --- custom_components/knmi/weather.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/knmi/weather.py b/custom_components/knmi/weather.py index b6ecda1..ba7a49e 100644 --- a/custom_components/knmi/weather.py +++ b/custom_components/knmi/weather.py @@ -129,6 +129,11 @@ def forecast(self): if super().getData(f"d{i}windkmh") is not None else None ) + sun_chance = ( + float(super().getData(f"d{i}zon")) + if super().getData(f"d{i}zon") is not None + else None + ) next_day = { ATTR_FORECAST_TIME: date.isoformat(), ATTR_FORECAST_CONDITION: condition, @@ -137,6 +142,7 @@ def forecast(self): ATTR_FORECAST_PRECIPITATION: precipitation, ATTR_FORECAST_WIND_BEARING: wind_bearing, ATTR_FORECAST_WIND_SPEED: wind_speed, + "sun_chance": sun_chance, } forecast.append(next_day) From 3d63f5f3e22c9546b36f1856fe9c83612831a351 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 15:47:45 +0000 Subject: [PATCH 2/6] Use more consts from HA --- custom_components/knmi/const.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/custom_components/knmi/const.py b/custom_components/knmi/const.py index 97372e6..6b34281 100644 --- a/custom_components/knmi/const.py +++ b/custom_components/knmi/const.py @@ -7,6 +7,8 @@ from homeassistant.components.binary_sensor import ( DEVICE_CLASS_SAFETY, ) +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT +from homeassistant.components.sensor.const import CONF_STATE_CLASS from homeassistant.components.weather import ( ATTR_CONDITION_CLEAR_NIGHT, ATTR_CONDITION_CLOUDY, @@ -20,9 +22,6 @@ ATTR_CONDITION_SUNNY, ) -# Todo, import next: from homeassistant.components.sensor import SensorStateClass -MEASUREMENT = "measurement" - # Base component constants. NAME = "KNMI" DOMAIN = "knmi" @@ -72,8 +71,8 @@ "device_class": DEVICE_CLASS_TEMPERATURE, "attributes": [ { - "name": "state_class", - "value": MEASUREMENT, + "name": CONF_STATE_CLASS, + "value": STATE_CLASS_MEASUREMENT, }, ], }, @@ -85,8 +84,8 @@ "device_class": DEVICE_CLASS_TEMPERATURE, "attributes": [ { - "name": "state_class", - "value": MEASUREMENT, + "name": CONF_STATE_CLASS, + "value": STATE_CLASS_MEASUREMENT, }, ], }, From 95df5821bf428b34d675319d5389553e2d34adc5 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 15:48:04 +0000 Subject: [PATCH 3/6] Update container config --- .devcontainer/devcontainer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fab8c1f..729d669 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ // See https://aka.ms/vscode-remote/devcontainer.json for format details. { "image": "ludeeus/container:integration-debian", - "name": "Blueprint integration development", + "name": "HA KNMI development", "context": "..", "appPort": [ "9123:8123" @@ -16,7 +16,7 @@ "settings": { "files.eol": "\n", "editor.tabSize": 4, - "terminal.integrated.shell.linux": "/bin/bash", + "terminal.integrated.defaultProfile.linux": "bash", "python.pythonPath": "/usr/bin/python3", "python.analysis.autoSearchPaths": false, "python.linting.pylintEnabled": true, From d7a652c9c890e56f8c8322a3b3ea42bf9a107309 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 15:48:21 +0000 Subject: [PATCH 4/6] Set pytest in vsc --- .vscode/settings.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a3d535d..aea87d4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,10 @@ "python.pythonPath": "/usr/local/bin/python", "files.associations": { "*.yaml": "home-assistant" - } + }, + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true } \ No newline at end of file From 0c88de0deb991912be5cd9617bdaa4c641772b14 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 15:48:30 +0000 Subject: [PATCH 5/6] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 1e7d3c0..705730d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 golles +Copyright (c) 2022 golles Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 47d4a35a6dc52c666a0081afd4f076f705b25732 Mon Sep 17 00:00:00 2001 From: golles Date: Fri, 4 Feb 2022 16:05:24 +0000 Subject: [PATCH 6/6] import ATTR_STATE_CLASS instead of CONF_STATE_CLASS --- custom_components/knmi/const.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/knmi/const.py b/custom_components/knmi/const.py index 6b34281..be1c4fa 100644 --- a/custom_components/knmi/const.py +++ b/custom_components/knmi/const.py @@ -7,8 +7,10 @@ from homeassistant.components.binary_sensor import ( DEVICE_CLASS_SAFETY, ) -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT -from homeassistant.components.sensor.const import CONF_STATE_CLASS +from homeassistant.components.sensor import ( + STATE_CLASS_MEASUREMENT, + ATTR_STATE_CLASS, +) from homeassistant.components.weather import ( ATTR_CONDITION_CLEAR_NIGHT, ATTR_CONDITION_CLOUDY, @@ -71,7 +73,7 @@ "device_class": DEVICE_CLASS_TEMPERATURE, "attributes": [ { - "name": CONF_STATE_CLASS, + "name": ATTR_STATE_CLASS, "value": STATE_CLASS_MEASUREMENT, }, ], @@ -84,7 +86,7 @@ "device_class": DEVICE_CLASS_TEMPERATURE, "attributes": [ { - "name": CONF_STATE_CLASS, + "name": ATTR_STATE_CLASS, "value": STATE_CLASS_MEASUREMENT, }, ],