Skip to content

Commit d4b4b8f

Browse files
committed
Catch up with HA, cleanuip, remove setspeed
1 parent c06df2a commit d4b4b8f

9 files changed

Lines changed: 231 additions & 149 deletions

File tree

.devcontainer/configuration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ configurator:
1010
http:
1111
api:
1212

13-
# debugpy:
13+
#debugpy:
1414
# wait: true
1515

16+
logger:
17+
default: warning
18+
logs:
19+
custom_components.dukaone: debug

.devcontainer/devcontainer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "DukaOne",
3-
"image": "ludeeus/container:integration",
3+
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
44
"context": "..",
55
"postCreateCommand": "",
66
"runArgs": [],
@@ -25,15 +25,15 @@
2525
"ms-python.python",
2626
"github.vscode-pull-request-github",
2727
"ryanluker.vscode-coverage-gutters",
28-
"ms-python.vscode-pylance"
28+
"ms-python.vscode-pylance",
2929
// "eamodio.gitlens",
3030
// "dbaeumer.vscode-eslint",
31-
// "esbenp.prettier-vscode",
31+
"esbenp.prettier-vscode",
3232
// "bierner.lit-html",
3333
// "runem.lit-plugin",
3434
// "auchenberg.vscode-browser-preview",
35-
// "davidanson.vscode-markdownlint",
36-
// "redhat.vscode-yaml",
35+
"davidanson.vscode-markdownlint",
36+
"redhat.vscode-yaml",
3737
// "oderwat.indent-rainbow"
3838
],
39-
}
39+
}

.vscode/settings.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{
2-
"python.formatting.provider": "black",
3-
"python.pythonPath": "/usr/bin/python3",
4-
"files.associations": {
5-
"*.yaml": "home-assistant"
6-
}
7-
}
2+
"editor.tabSize": 2,
3+
"editor.insertSpaces": true,
4+
"editor.formatOnSave": true,
5+
"python.formatting.provider": "black",
6+
"python.linting.flake8Enabled": false,
7+
"python.linting.flake8Args": ["--max-line-length=120"],
8+
"python.linting.enabled": true,
9+
"python.linting.pydocstyleEnabled": false,
10+
"python.linting.pydocstyleArgs": ["--max-line-length=120"],
11+
"python.linting.pylintEnabled": true,
12+
"python.linting.pycodestyleEnabled": false,
13+
"python.linting.pycodestyleArgs": ["--max-line-length=120"],
14+
"python.pythonPath": "/usr/bin/python3",
15+
"files.associations": {
16+
"*.yaml": "home-assistant"
17+
}
18+
}

custom_components/dukaone/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from homeassistant.core import HomeAssistant
1111
from homeassistant.helpers.entity_component import EntityComponent
1212

13-
from dukaonesdk.dukaclient import DukaClient
13+
from dukaonesdk.dukaclient import DukaClient, Device
1414

1515
from .const import DOMAIN
1616

@@ -54,14 +54,15 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
5454

5555

5656
class DukaEntityComponent(EntityComponent):
57-
""" We only want to have one instance of the dukaclient."""
57+
"""We only want to have one instance of the dukaclient."""
5858

5959
def __init__(self, hass):
6060
super(DukaEntityComponent, self).__init__(_LOGGER, DOMAIN, hass)
6161
self._the_client = None
6262

6363
@property
6464
def the_client(self) -> DukaClient:
65+
"""Get the duka one client."""
6566
if self._the_client is None:
6667
self._the_client = DukaClient()
6768
return self._the_client

custom_components/dukaone/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def dovalidate(hass: HomeAssistantType, user_input):
31-
31+
"""Validate if we can connect to the device"""
3232
if DOMAIN not in hass.data:
3333
hass.data[DOMAIN] = DukaEntityComponent(hass)
3434
component: DukaEntityComponent = hass.data[DOMAIN]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""" """
2+
import asyncio
3+
import logging
4+
import time
5+
from xmlrpc.client import boolean
6+
7+
from dukaonesdk.device import Device
8+
from dukaonesdk.dukaclient import DukaClient
9+
10+
from homeassistant.helpers.typing import HomeAssistantType
11+
12+
from . import DukaEntityComponent
13+
from .const import DOMAIN
14+
15+
_LOGGER = logging.getLogger(__name__)
16+
17+
18+
class DukaEntity:
19+
"""Implement the base of a duka entity with a reference to a device"""
20+
21+
def __init__(self, hass: HomeAssistantType, device_id):
22+
self._device_id = device_id
23+
self.device: Device = None
24+
component: DukaEntityComponent = hass.data[DOMAIN]
25+
self.the_client: DukaClient = component.the_client
26+
27+
def initialize_device(self, password: str, ip_address: str) -> None:
28+
"""Initialize the duka one device"""
29+
self.device = self.the_client.add_device(
30+
self._device_id,
31+
password,
32+
ip_address,
33+
self.on_change,
34+
)
35+
36+
async def wait_for_device_to_be_ready(self) -> boolean:
37+
"""Wait for the device to reponse to the initial get firmware version command."""
38+
timeout = time.time() + 10
39+
while self.device is None or self.device.firmware_version is None:
40+
if time.time() > timeout:
41+
return False
42+
await asyncio.sleep(0.1)
43+
return True
44+
45+
def on_change(self, device: Device):
46+
"""Callback whe dukaone has changes - must be implemented in derived class"""
47+
raise NotImplementedError()
48+
49+
def dukaone_device_info(self):
50+
"""Return device information."""
51+
if self.device is None:
52+
return None
53+
info = {
54+
"name": "DukaOne",
55+
"identifiers": {(DOMAIN, self._device_id)},
56+
"manufacturer": "Duka Ventilation",
57+
"model": f"Type {self.device.unit_type}",
58+
"sw_version": f"{self.device.firmware_version} {self.device.firmware_date}",
59+
}
60+
return info

0 commit comments

Comments
 (0)