Skip to content

Commit 4810a9c

Browse files
committed
Move logging and constant to constants.py
1 parent c251838 commit 4810a9c

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

plugwise/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""Plugwise Stick and Smile constants."""
2+
import logging
3+
4+
LOGGER = logging.getLogger(__name__)
25

36
# Copied homeassistant.consts
47
ATTR_DEVICE_CLASS = "device_class"
@@ -365,6 +368,15 @@
365368
STATUS = "/system/status.xml"
366369

367370
ATTR_TYPE = "type"
371+
DAYS = {
372+
"mo": 0,
373+
"tu": 1,
374+
"we": 2,
375+
"th": 3,
376+
"fr": 4,
377+
"sa": 5,
378+
"su": 6,
379+
}
368380
DEFAULT_TIMEOUT = 30
369381
DEFAULT_USERNAME = "smile"
370382
DEFAULT_PORT = 80

plugwise/helper.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import asyncio
55
import datetime as dt
6-
import logging
76

87
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
98
from aiohttp import BasicAuth, ClientSession, ClientTimeout, ServerTimeoutError
@@ -20,13 +19,15 @@
2019
ATTR_TYPE,
2120
ATTR_UNIT_OF_MEASUREMENT,
2221
BINARY_SENSORS,
22+
DAYS,
2323
DEVICE_MEASUREMENTS,
2424
ENERGY_KILO_WATT_HOUR,
2525
ENERGY_WATT_HOUR,
2626
FAKE_LOC,
2727
HEATER_CENTRAL_MEASUREMENTS,
2828
HOME_MEASUREMENTS,
2929
LOCATIONS,
30+
LOGGER,
3031
POWER_WATT,
3132
SENSORS,
3233
SWITCH_GROUP_TYPES,
@@ -46,17 +47,6 @@
4647
version_to_model,
4748
)
4849

49-
_LOGGER = logging.getLogger(__name__)
50-
51-
DAYS = {
52-
"mo": 0,
53-
"tu": 1,
54-
"we": 2,
55-
"th": 3,
56-
"fr": 4,
57-
"sa": 5,
58-
"su": 6,
59-
}
6050

6151

6252
def pw_notification_updater(devs, d_id, d_dict, notifs):
@@ -223,14 +213,14 @@ async def _request_validate(self, resp, method):
223213

224214
result = await resp.text()
225215
if not result or "<error>" in result:
226-
_LOGGER.error("Smile response empty or error in %s", result)
216+
LOGGER.error("Smile response empty or error in %s", result)
227217
raise ResponseError
228218

229219
try:
230220
# Encode to ensure utf8 parsing
231221
xml = etree.XML(escape_illegal_xml_characters(result).encode())
232222
except etree.ParseError:
233-
_LOGGER.error("Smile returns invalid XML for %s", self._endpoint)
223+
LOGGER.error("Smile returns invalid XML for %s", self._endpoint)
234224
raise InvalidXMLError
235225

236226
return xml
@@ -265,7 +255,7 @@ async def _request(
265255
)
266256
except ServerTimeoutError:
267257
if retry < 1:
268-
_LOGGER.error("Timed out sending command to Plugwise: %s", command)
258+
LOGGER.error("Timed out sending command to Plugwise: %s", command)
269259
raise DeviceTimeoutError
270260
return await self._request(command, retry - 1)
271261

0 commit comments

Comments
 (0)