Skip to content

Commit

Permalink
Merge pull request #24 from LaggAt/feature/small_updates_and_fixes
Browse files Browse the repository at this point in the history
Feature/small updates and fixes
  • Loading branch information
LaggAt authored Apr 25, 2021
2 parents 85fb85d + 04bb70f commit f8644e3
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 114 deletions.
12 changes: 7 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
// ],
"postCreateCommand": "/bin/chmod +x /workspaces/hacs-govee/.devcontainer/postCreateContainer.sh && /workspaces/hacs-govee/.devcontainer/postCreateContainer.sh",
"extensions": [
"ms-python.python",
"cschleiden.vscode-github-actions",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance",
"littlefoxteam.vscode-python-test-adapter",
"hbenl.vscode-test-explorer",
"knisterpeter.vscode-github",
"littlefoxteam.vscode-python-test-adapter",
"mhutchie.git-graph",
"ms-python.python",
"ms-python.vscode-pylance",
"ryanluker.vscode-coverage-gutters",
"tht13.python",
"mhutchie.git-graph"
],
"settings": {
"files.eol": "\n",
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/cron.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/hacs-hass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: HACS/HASS Actions

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
hacs:
name: HACS Action
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: HACS Action
uses: "hacs/action@main"
with:
category: "integration"

hassfest:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: home-assistant/actions/hassfest@master
31 changes: 0 additions & 31 deletions .github/workflows/pull.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/push.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Style check

on:
push:
pull_request:

jobs:
style:
runs-on: "ubuntu-latest"
name: Check style formatting
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
with:
python-version: "3.x"
- run: python3 -m pip install black
- run: black .
25 changes: 25 additions & 0 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test wtih tox

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# NOTE: keep this in sync with envlist in tox.ini
python-version: [3.9]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"name": "Launch Home Assistant UI in Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://192.168.144.5:9123
",
"url": "http://192.168.144.5:9123",
"webRoot": "${workspaceFolder}"
},
{
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The Govee integration allows you to control and monitor lights using the Govee A
To set up this integration, click Configuration in the sidebar and then click Integrations. Click the + icon to add "Govee" to the integrations. An API key
is necessary, you need to obtain it in the 'Govee Home' app on your mobile, in the User menu - About us - Apply for API Key. The key will be sent to you by email.

## Sponsor

A lot of effort is going into that integration. So if you can afford it and want to support us:

<a href="https://www.buymeacoffee.com/LaggAt" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

Thank you!

## Pulling or assuming state

Some devices do not support pulling state. In this case we assume the state on your last input.
Expand Down
21 changes: 20 additions & 1 deletion custom_components/govee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
await _unload_component_entry(hass, entry, component)
for component in PLATFORMS
]
)
Expand All @@ -93,3 +93,22 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
await hub.close()

return unload_ok


async def _unload_component_entry(
hass: HomeAssistant, entry: ConfigEntry, component: str
) -> bool:
"""Unload an entry for a specific component."""
success = False
try:
success = await hass.config_entries.async_forward_entry_unload(entry, component)
except ValueError:
# probably ValueError: Config entry was never loaded!
return success
except Exception as ex:
_LOGGER.warning(
"Continuing on exception when unloading %s component's entry: %s",
component,
ex,
)
return success
4 changes: 2 additions & 2 deletions custom_components/govee/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"codeowners": ["@LaggAt"],
"domain": "govee",
"name": "Govee",
"version": "0.1.9",
"version": "0.1.10",
"config_flow": true,
"documentation": "https://github.com/LaggAt/hacs-govee/blob/master/README.md",
"issue_tracker": "https://github.com/LaggAt/hacs-govee/issues",
"requirements": ["govee-api-laggat==0.1.40", "dacite==1.6.0"],
"requirements": ["govee-api-laggat==0.1.41", "dacite==1.6.0"],
"ssdp": [],
"zeroconf": [],
"homekit": {},
Expand Down
6 changes: 3 additions & 3 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "govee",
"hacs": "0.1.9",
"hacs": "0.1.10",
"domains": [
"light"
],
"iot_class": "Cloud Polling",
"homeassistant": "0.118.4"
"iot_class": ["Assumed State", "Cloud Polling"],
"homeassistant": "2021.4.5"
}
17 changes: 9 additions & 8 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
tox
pytest-homeassistant-custom-component==0.0.21
homeassistant==0.118.4
govee_api_laggat
flake8
pytest
pytest-cov
coveralls
black==20.8b1
colorlog==4.6.2
coveralls
dacite==1.6.0
flake8
govee_api_laggat
homeassistant
pylint==2.6.0
pytest
pytest-cov
pytest-homeassistant-custom-component==0.3.0
tox
11 changes: 6 additions & 5 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from homeassistant import config_entries, setup
from custom_components.govee.const import DOMAIN
from homeassistant.const import CONF_API_KEY, CONF_DELAY
from homeassistant.core import HomeAssistant

# from tests.async_mock import patch
from pytest_homeassistant_custom_component.async_mock import patch
from unittest.mock import patch


async def test_form(hass):
async def test_form(hass: HomeAssistant):
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
Expand Down Expand Up @@ -38,7 +39,7 @@ async def test_form(hass):
assert len(mock_setup_entry.mock_calls) == 1


async def test_form_cannot_connect(hass):
async def test_form_cannot_connect(hass: HomeAssistant):
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
Expand All @@ -54,10 +55,10 @@ async def test_form_cannot_connect(hass):
)

assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"}
assert result2["errors"] == {"api_key": "cannot_connect"}


async def test_form_unknown_exception(hass):
async def test_form_unknown_exception(hass: HomeAssistant):
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
Expand Down
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
[tox]
envlist = py{37,39}
envlist = py{39}
skipsdist=True

[gh-actions]
python =
3.9: py39

[testenv]
basepython =
py37: python3.7
py39: python3.9
deps =
flake8
-r{toxinidir}/requirements_test.txt
commands =
flake8 .
pytest

[flake8]
max-line-length = 119
Expand Down

0 comments on commit f8644e3

Please sign in to comment.