From 25a1ed21c3c7d4b2f16c27dbb594a30842ac70ad Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 12:20:41 +0100 Subject: [PATCH 1/8] Fix HACS validation errors by updating hacs.json and manifest.json - Removed invalid 'domains', 'country', and 'homeassistant' keys from hacs.json. - Added 'content_in_root' and 'render_readme' keys to hacs.json. - Added the required 'issue_tracker' key to manifest.json. --- .../hass_stadtreinigung_hamburg/manifest.json | 3 ++- hacs.json | 12 ++++-------- requirements_test.txt | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/custom_components/hass_stadtreinigung_hamburg/manifest.json b/custom_components/hass_stadtreinigung_hamburg/manifest.json index 6f3b85b..ed016d3 100644 --- a/custom_components/hass_stadtreinigung_hamburg/manifest.json +++ b/custom_components/hass_stadtreinigung_hamburg/manifest.json @@ -2,6 +2,7 @@ "domain": "stadtreinigung_hamburg", "name": "Stadtreinigung Hamburg", "documentation": "https://github.com/custom-components/sensor.stadtreinigung_hamburg", + "issue_tracker": "https://github.com/custom-components/sensor.stadtreinigung_hamburg/issues", "dependencies": [], "codeowners": [ "@vigonotion" @@ -11,5 +12,5 @@ "lxml_html_clean" ], "config_flow": true, - "version": "1.1.2" + "version": "1.1.5" } diff --git a/hacs.json b/hacs.json index 3266572..deea251 100644 --- a/hacs.json +++ b/hacs.json @@ -1,10 +1,6 @@ { "name": "Stadtreinigung Hamburg", - "domains": [ - "sensor" - ], - "country": "DE", - "homeassistant": "0.109.0", - "zip_release": true, - "filename": "stadtreinigung_hamburg.zip" -} \ No newline at end of file + "content_in_root": false, + "filename": "stadtreinigung_hamburg.zip", + "render_readme": true +} diff --git a/requirements_test.txt b/requirements_test.txt index c8afe28..fd5c257 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1 +1 @@ -pytest-homeassistant-custom-component==0.3.0 \ No newline at end of file +pytest-homeassistant-custom-component==0.12.49 From d496616fcb5a0afb4875d1d97ad868e29148faf9 Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 12:31:49 +0100 Subject: [PATCH 2/8] Update python version to 3.10 --- .github/workflows/pull.yml | 2 +- .github/workflows/push.yml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index cb998e2..f3043b2 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -39,7 +39,7 @@ jobs: - name: Setup Python uses: "actions/setup-python@v1" with: - python-version: "3.8" + python-version: "3.10" - name: Install requirements run: python3 -m pip install -r requirements_test.txt - name: Run tests diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a775739..e4c34ea 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -27,9 +27,9 @@ jobs: name: Check style formatting steps: - uses: "actions/checkout@v2" - - uses: "actions/setup-python@v1" + - uses: "actions/setup-python@v4" with: - python-version: "3.x" + python-version: "3.10" - run: python3 -m pip install black - run: black . @@ -43,7 +43,7 @@ jobs: # - name: Setup Python # uses: "actions/setup-python@v1" # with: - # python-version: "3.8" + # python-version: "3.10" # - name: Install requirements # run: python3 -m pip install -r requirements_test.txt # - name: Run tests @@ -56,4 +56,4 @@ jobs: # --cov custom_components.stadtreinigung_hamburg \ # -o console_output_style=count \ # -p no:sugar \ - # tests \ No newline at end of file + # tests From ac2b968ea51eb25c84db8cd49b925fe0a0b81f45 Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 12:38:17 +0100 Subject: [PATCH 3/8] Rename dir to match domain in manifest --- .../__init__.py | 0 .../config_flow.py | 0 .../manifest.json | 0 .../sensor.py | 0 .../strings.json | 0 .../translations/de.json | 0 .../translations/en.json | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/__init__.py (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/config_flow.py (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/manifest.json (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/sensor.py (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/strings.json (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/translations/de.json (100%) rename custom_components/{hass_stadtreinigung_hamburg => stadtreinigung_hamburg}/translations/en.json (100%) diff --git a/custom_components/hass_stadtreinigung_hamburg/__init__.py b/custom_components/stadtreinigung_hamburg/__init__.py similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/__init__.py rename to custom_components/stadtreinigung_hamburg/__init__.py diff --git a/custom_components/hass_stadtreinigung_hamburg/config_flow.py b/custom_components/stadtreinigung_hamburg/config_flow.py similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/config_flow.py rename to custom_components/stadtreinigung_hamburg/config_flow.py diff --git a/custom_components/hass_stadtreinigung_hamburg/manifest.json b/custom_components/stadtreinigung_hamburg/manifest.json similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/manifest.json rename to custom_components/stadtreinigung_hamburg/manifest.json diff --git a/custom_components/hass_stadtreinigung_hamburg/sensor.py b/custom_components/stadtreinigung_hamburg/sensor.py similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/sensor.py rename to custom_components/stadtreinigung_hamburg/sensor.py diff --git a/custom_components/hass_stadtreinigung_hamburg/strings.json b/custom_components/stadtreinigung_hamburg/strings.json similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/strings.json rename to custom_components/stadtreinigung_hamburg/strings.json diff --git a/custom_components/hass_stadtreinigung_hamburg/translations/de.json b/custom_components/stadtreinigung_hamburg/translations/de.json similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/translations/de.json rename to custom_components/stadtreinigung_hamburg/translations/de.json diff --git a/custom_components/hass_stadtreinigung_hamburg/translations/en.json b/custom_components/stadtreinigung_hamburg/translations/en.json similarity index 100% rename from custom_components/hass_stadtreinigung_hamburg/translations/en.json rename to custom_components/stadtreinigung_hamburg/translations/en.json From f13e176a9d2b7d38e9777b04c38db6416efaad71 Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 12:46:33 +0100 Subject: [PATCH 4/8] Fix Hassfest validation errors --- custom_components/stadtreinigung_hamburg/__init__.py | 3 +++ custom_components/stadtreinigung_hamburg/manifest.json | 1 + 2 files changed, 4 insertions(+) diff --git a/custom_components/stadtreinigung_hamburg/__init__.py b/custom_components/stadtreinigung_hamburg/__init__.py index d8ac68b..380cfea 100644 --- a/custom_components/stadtreinigung_hamburg/__init__.py +++ b/custom_components/stadtreinigung_hamburg/__init__.py @@ -1,9 +1,12 @@ """The Stadtreinigung Hamburg integration""" from homeassistant.config_entries import ConfigEntry from homeassistant.core import Config, HomeAssistant +import homeassistant.helpers.config_validation as cv +from homeassistant.const import CONF_NAME DOMAIN = "stadtreinigung_hamburg" +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) async def async_setup(hass, config): """Do not allow config via configuration.yaml""" diff --git a/custom_components/stadtreinigung_hamburg/manifest.json b/custom_components/stadtreinigung_hamburg/manifest.json index ed016d3..0708b66 100644 --- a/custom_components/stadtreinigung_hamburg/manifest.json +++ b/custom_components/stadtreinigung_hamburg/manifest.json @@ -12,5 +12,6 @@ "lxml_html_clean" ], "config_flow": true, + "iot_class": "cloud_polling", "version": "1.1.5" } From 767d92c683c5f287f3ee255a790bf0bfef4c806d Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 12:51:15 +0100 Subject: [PATCH 5/8] update test requirements --- .github/workflows/pull.yml | 2 +- .github/workflows/push.yml | 4 ++-- requirements_test.txt | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index f3043b2..6c4ac35 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -39,7 +39,7 @@ jobs: - name: Setup Python uses: "actions/setup-python@v1" with: - python-version: "3.10" + python-version: "3.12" - name: Install requirements run: python3 -m pip install -r requirements_test.txt - name: Run tests diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e4c34ea..3d79570 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -29,7 +29,7 @@ jobs: - uses: "actions/checkout@v2" - uses: "actions/setup-python@v4" with: - python-version: "3.10" + python-version: "3.12" - run: python3 -m pip install black - run: black . @@ -43,7 +43,7 @@ jobs: # - name: Setup Python # uses: "actions/setup-python@v1" # with: - # python-version: "3.10" + # python-version: "3.12" # - name: Install requirements # run: python3 -m pip install -r requirements_test.txt # - name: Run tests diff --git a/requirements_test.txt b/requirements_test.txt index fd5c257..28b26d0 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1 +1,4 @@ -pytest-homeassistant-custom-component==0.12.49 +pytest-homeassistant-custom-component==0.13.45 +pytest==8.3.3 +pytest-cov==5.0.0 +pytest-xdist==3.6.1 From 70b940fffc241247d802d121896cfcb960328491 Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 13:06:08 +0100 Subject: [PATCH 6/8] Update requirements_test.txt --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 28b26d0..2c515d9 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,4 +1,4 @@ -pytest-homeassistant-custom-component==0.13.45 +pytest-homeassistant-custom-component==0.13.175 pytest==8.3.3 pytest-cov==5.0.0 pytest-xdist==3.6.1 From 6c5423a2ffe14d8864d811b97c2b8e1adfadb0c4 Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 13:09:55 +0100 Subject: [PATCH 7/8] Add pytest.ini --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..0102b0a --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +asyncio_default_fixture_loop_scope = function From c5610ef387aac4e94d8136d969abc9e8b73cc6ef Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 13:15:49 +0100 Subject: [PATCH 8/8] Add a basic test --- .github/workflows/pull.yml | 1 + pytest.ini | 6 +++++- tests/__init__.py | 0 tests/conftest.py | 1 + tests/test_init.py | 25 +++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_init.py diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 6c4ac35..cc49672 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -50,6 +50,7 @@ jobs: --durations=10 \ -n auto \ --cov custom_components.stadtreinigung_hamburg \ + --cov-report=term-missing \ -o console_output_style=count \ -p no:sugar \ tests diff --git a/pytest.ini b/pytest.ini index 0102b0a..cdce43f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,6 @@ [pytest] -asyncio_default_fixture_loop_scope = function +asyncio_mode = auto +testpaths = tests +python_files = test_*.py +python_classes = Test* +python_functions = test_* diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..688ce23 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +pytest_plugins = ["pytest_homeassistant_custom_component"] diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..19af053 --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,25 @@ +import pytest +from homeassistant.setup import async_setup_component +from homeassistant.const import STATE_UNKNOWN + +@pytest.mark.asyncio +async def test_setup(hass, enable_custom_integrations): + """Test that the component can be setup and creates sensors.""" + config = { + 'stadtreinigung_hamburg': { + 'name': 'Test Sensor', + 'street': 'Jungfernstieg', + 'number': '1', + } + } + assert await async_setup_component(hass, 'stadtreinigung_hamburg', config) + await hass.async_block_till_done() + + # Check that the component is loaded + assert 'stadtreinigung_hamburg' in hass.config.components + + # Verify that sensors are created + state = hass.states.get('sensor.test_sensor') + assert state is not None + assert state.state != STATE_UNKNOWN +