Skip to content

Commit a9dd4aa

Browse files
fixes
1 parent a0f0def commit a9dd4aa

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

custom_components/invicta/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from enum import Enum
55
import time
66
import aiohttp
7+
from aiohttp import ClientOSError
78

89
from custom_components.invicta.winet.model import WinetGetRegisterResult
910
from custom_components.invicta.winet.winet import WinetAPILocal
@@ -265,6 +266,7 @@ class InvictaApiClient:
265266
failed_poll_attempts = 0
266267
is_sending = False
267268
is_polling_in_background = False
269+
stove_ip = ""
268270

269271
def __init__(self, session: aiohttp.ClientSession, host: str) -> None:
270272
"""init"""
@@ -275,6 +277,7 @@ def __init__(self, session: aiohttp.ClientSession, host: str) -> None:
275277
self._should_poll_in_background = False
276278
self._bg_task: Task | None = None
277279

280+
self.stove_ip = host
278281
self.is_polling_in_background = False
279282
self.is_sending = False
280283
self.failed_poll_attempts = 0

custom_components/invicta/coordinator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def device_info(self) -> DeviceInfo:
6969
manufacturer="Invicta",
7070
model="Fontica 8",
7171
name=self.read_api.data.name,
72-
identifiers={("Invicta", f"{self.read_api.data.productmodel}]")},
72+
identifiers={("Invicta", f"{self.read_api.data.model}]")},
7373
sw_version="1.0",
7474
configuration_url=f"http://{self._api.stove_ip}/",
7575
)

custom_components/invicta/entity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ def __init__(
2424
self._attr_name = f"Stove {description.name}"
2525

2626
# no serial number. generate unique id ?
27-
self._attr_unique_id = (
28-
f"{description.key}_{coordinator.read_api.data.productmodel}"
29-
)
27+
self._attr_unique_id = f"{description.key}_{coordinator.read_api.data.model}"
3028
# Configure the Device Info
3129
self._attr_device_info = self.coordinator.device_info

custom_components/invicta/winet/winet.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Winet-Control API"""
22
from __future__ import annotations
3-
import logging as _log
3+
import logging
4+
45
from json import JSONDecodeError
56

67
import aiohttp
@@ -17,6 +18,8 @@
1718
WinetRegisterCategory,
1819
)
1920

21+
LOGGER = logging.getLogger(__package__)
22+
2023

2124
class WinetAPILocal:
2225
"""Bottom level API. handle http communication with the local winet module"""
@@ -51,35 +54,35 @@ async def get_registers(
5154
"Origin": f"http://{self._stove_ip}",
5255
"Referer": f"http://{self._stove_ip}/management.html",
5356
}
54-
_log.warning(f"Querying {url} with data={data}")
57+
LOGGER.debug(f"Querying {url} with data={data}")
5558
try:
5659
async with session.post(url, data=data, headers=headers) as response:
5760
try:
5861
if response.status != 200:
59-
_log.warning(f"Error accessing {url} - {response.status}")
62+
LOGGER.warning(f"Error accessing {url} - {response.status}")
6063
raise ConnectionError(
6164
f"Communication error - Response status {response.status}"
6265
)
6366
try:
6467
json_data = await response.json(content_type=None)
65-
_log.warning("Received: %s", json_data)
68+
LOGGER.debug("Received: %s", json_data)
6669

6770
if "result" in json_data:
6871
# handle an action's result
6972
if json_data["result"] is False:
70-
_log.warning("Api result is False")
73+
LOGGER.warning("Api result is False")
7174
else:
7275
try:
7376
return WinetGetRegisterResult(**json_data)
7477
except Exception:
75-
_log.warning("Error parsing poll data")
76-
_log.warning(f"Received: {json_data}")
78+
LOGGER.warning("Error parsing poll data")
79+
LOGGER.debug(f"Received: {json_data}")
7780
# TODO: what about model check exceptions ?
7881
except JSONDecodeError:
79-
_log.warning("Error decoding JSON: [%s]", response.text)
82+
LOGGER.warning("Error decoding JSON: [%s]", response.text)
8083

8184
except ConnectionError as exc:
82-
_log.warning(f"Connection Error accessing {url}")
85+
LOGGER.warning(f"Connection Error accessing {url}")
8386
raise ConnectionError(
8487
"ConnectionError - host not found"
8588
) from exc
@@ -92,7 +95,7 @@ async def get_registers(
9295
):
9396
raise ConnectionError()
9497
except Exception as unknown_error:
95-
_log.error("Unhandled Exception %s", type(unknown_error))
98+
LOGGER.error("Unhandled Exception %s", type(unknown_error))
9699

97100
async def set_register(
98101
self, registerid: WinetRegister, value: int, key="002", memory=1
@@ -118,27 +121,27 @@ async def set_register(
118121
"Origin": f"http://{self._stove_ip}",
119122
"Referer": f"http://{self._stove_ip}/management.html",
120123
}
121-
_log.debug(f"Posting to {url}, data={data}")
124+
LOGGER.debug(f"Posting to {url}, data={data}")
122125
try:
123126
async with session.post(url, data=data, headers=headers) as response:
124127
try:
125128
# TODO: log others error responses codes
126129
if response.status != 200:
127130
# Valid address - but poll endpoint not found
128-
_log.warning(f"Error accessing {url} - {response.status}")
131+
LOGGER.warning(f"Error accessing {url} - {response.status}")
129132
raise ConnectionError(
130133
f"Error accessing {url} - {response.status}"
131134
)
132135
try:
133136
# returns {'result': False} if failed (or True if success)
134137
json_data = await response.json(content_type=None)
135138
if json_data["result"] is not True:
136-
_log.warning("Received: %s", json_data)
139+
LOGGER.debug("Received: %s", json_data)
137140

138141
except JSONDecodeError:
139-
_log.warning("Error decoding JSON: [%s]", response.text)
142+
LOGGER.warning("Error decoding JSON: [%s]", response.text)
140143
except ConnectionError as exc:
141-
_log.warning(f"Connection Error accessing {url}")
144+
LOGGER.warning(f"Connection Error accessing {url}")
142145
raise ConnectionError(
143146
"ConnectionError - host not found"
144147
) from exc
@@ -152,4 +155,4 @@ async def set_register(
152155
) as exc:
153156
raise ConnectionError() from exc
154157
except Exception as unknown_error:
155-
_log.error("Unhandled Exception %s", type(unknown_error))
158+
LOGGER.error("Unhandled Exception %s", type(unknown_error))

0 commit comments

Comments
 (0)