Skip to content

Commit 325c59d

Browse files
committed
minor tweaks
1 parent 7ef5718 commit 325c59d

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

custom_components/tibber_local/__init__.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import asyncio
22
import logging
33
import re
4-
5-
import voluptuous as vol
6-
74
from datetime import timedelta
8-
from smllib import SmlStreamReader
9-
from smllib.errors import CrcError
10-
from smllib.sml import SmlListEntry, ObisCode
11-
from smllib.const import UNITS
125

6+
import voluptuous as vol
137
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
148
from homeassistant.const import CONF_ID, CONF_HOST, CONF_SCAN_INTERVAL, CONF_PASSWORD, CONF_MODE
159
from homeassistant.core import HomeAssistant
1610
from homeassistant.exceptions import ConfigEntryNotReady
1711
from homeassistant.helpers.aiohttp_client import async_get_clientsession
1812
from homeassistant.helpers.entity import EntityDescription, Entity
1913
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
14+
from smllib import SmlStreamReader
15+
from smllib.const import UNITS
16+
from smllib.errors import CrcError
17+
from smllib.sml import SmlListEntry, ObisCode
2018

2119
from .const import (
2220
DOMAIN,
@@ -30,6 +28,8 @@
3028
MODE_0_AutoScanMode,
3129
MODE_3_SML_1_04,
3230
MODE_99_PLAINTEXT,
31+
MODE_1_IEC_62056_21,
32+
ENUM_IMPLEMENTATIONS,
3333
)
3434

3535
_LOGGER = logging.getLogger(__name__)
@@ -255,6 +255,10 @@ async def detect_com_mode(self):
255255
elif self._com_mode == MODE_0_AutoScanMode:
256256
await self._check_modes_internal(MODE_3_SML_1_04, MODE_99_PLAINTEXT)
257257

258+
# finally raise value error if not implemented yet!
259+
if self._com_mode not in ENUM_IMPLEMENTATIONS:
260+
raise ValueError(f"NOT IMPLEMENTED yet! - Mode: {self._com_mode}")
261+
258262
async def _check_modes_internal(self, mode_1:int, mode_2:int):
259263
_LOGGER.debug(f"detect_com_mode is {self._com_mode}: will try to read {mode_1}")
260264
await self.read_tibber_local(mode_1, False, log_payload=True)
@@ -304,6 +308,8 @@ async def read_tibber_local(self, mode: int, retry: bool, log_payload: bool = Fa
304308
if res.status == 200:
305309
if mode == MODE_3_SML_1_04:
306310
await self.read_sml(await res.read(), retry, log_payload)
311+
#elif mode == MODE_1_IEC_62056_21:
312+
# await self.read_ice62056(await res.read(), retry, log_payload)
307313
elif mode == MODE_99_PLAINTEXT:
308314
await self.read_plaintext(await res.text(), retry, log_payload)
309315
else:

custom_components/tibber_local/config_flow.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ async def _test_connection_tibber_local(self, host, pwd, node_num):
5555
try:
5656
bridge = TibberLocalBridge(host=host, pwd=pwd, websession=async_get_clientsession(self.hass),
5757
node_num=node_num)
58-
await bridge.detect_com_mode()
59-
if bridge._com_mode in ENUM_IMPLEMENTATIONS:
60-
self._con_mode = bridge._com_mode
61-
return await self._test_data_available(bridge, host)
62-
else:
58+
try:
59+
await bridge.detect_com_mode()
60+
if bridge._com_mode in ENUM_IMPLEMENTATIONS:
61+
self._con_mode = bridge._com_mode
62+
return await self._test_data_available(bridge, host)
63+
else:
64+
self._errors[CONF_HOST] = "unknown_mode"
65+
66+
except ValueError as val_err:
6367
self._errors[CONF_HOST] = "unknown_mode"
68+
_LOGGER.warning(f"ValueError: {val_err}")
6469

6570
except (OSError, HTTPError, Timeout, ClientResponseError):
6671
self._errors[CONF_HOST] = "cannot_connect"

custom_components/tibber_local/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"iot_class": "local_polling",
1111
"issue_tracker": "https://github.com/marq24/ha-tibber-pulse-local/issues",
1212
"requirements": ["smllib==1.4"],
13-
"version": "2024.6.1"
13+
"version": "2024.6.2"
1414
}

0 commit comments

Comments
 (0)