Skip to content

Commit 713a44d

Browse files
authored
Merge pull request #19 from plugwise/merge-exceptions
Merge Exception Class
2 parents dc36593 + 2fe137a commit 713a44d

File tree

5 files changed

+29
-96
lines changed

5 files changed

+29
-96
lines changed

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.8.0a5"
3+
__version__ = "0.8.0a6"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import stick

plugwise/constants.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
""" Plugwise Stick and Smile constants."""
2+
13
### Stick constants ###
24

35
UTF8_DECODE = "utf-8"
@@ -327,40 +329,14 @@
327329
}
328330

329331
SMILES = {
330-
"smile_open_therm_v3": {
331-
"type": "thermostat",
332-
"friendly_name": "Adam",
333-
},
334-
"smile_open_therm_v2": {
335-
"type": "thermostat",
336-
"friendly_name": "Adam",
337-
},
338-
"smile_thermo_v4": {
339-
"type": "thermostat",
340-
"friendly_name": "Anna",
341-
},
342-
"smile_thermo_v3": {
343-
"type": "thermostat",
344-
"friendly_name": "Anna",
345-
},
346-
"smile_thermo_v1": {
347-
"type": "thermostat",
348-
"friendly_name": "Anna",
349-
"legacy": True,
350-
},
351-
"smile_v4": {
352-
"type": "power",
353-
"friendly_name": "P1",
354-
},
355-
"smile_v3": {
356-
"type": "power",
357-
"friendly_name": "P1",
358-
},
359-
"smile_v2": {
360-
"type": "power",
361-
"friendly_name": "P1",
362-
"legacy": True,
363-
},
332+
"smile_open_therm_v3": {"type": "thermostat", "friendly_name": "Adam",},
333+
"smile_open_therm_v2": {"type": "thermostat", "friendly_name": "Adam",},
334+
"smile_thermo_v4": {"type": "thermostat", "friendly_name": "Anna",},
335+
"smile_thermo_v3": {"type": "thermostat", "friendly_name": "Anna",},
336+
"smile_thermo_v1": {"type": "thermostat", "friendly_name": "Anna", "legacy": True,},
337+
"smile_v4": {"type": "power", "friendly_name": "P1",},
338+
"smile_v3": {"type": "power", "friendly_name": "P1",},
339+
"smile_v2": {"type": "power", "friendly_name": "P1", "legacy": True,},
364340
"stretch_v3": {"type": "stretch", "friendly_name": "Stretch", "legacy": True},
365341
"stretch_v2": {"type": "stretch", "friendly_name": "Stretch", "legacy": True},
366342
}

plugwise/exceptions.py

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,71 @@
1-
# Copyright (C) 2011 Sven Petai <[email protected]>
2-
# Use of this source code is governed by the MIT license found in the LICENSE file.
1+
""" Copyright (C) 2011 Sven Petai <[email protected]>, use of this source code is governed by the MIT license found in the LICENSE file."""
32

4-
### Stick exceptions ###
53

64
class PlugwiseException(Exception):
75
"""Base error class for this Plugwise library"""
86

9-
pass
7+
8+
### Stick exceptions ###
109

1110

1211
class PortError(PlugwiseException):
1312
"""Connection to USBstick failed"""
1413

15-
pass
16-
1714

1815
class StickInitError(PlugwiseException):
1916
"""Initialization of USBstick failed"""
2017

21-
pass
22-
2318

2419
class NetworkDown(PlugwiseException):
2520
"""Zigbee network not online"""
2621

27-
pass
28-
2922

3023
class CirclePlusError(PlugwiseException):
3124
"""Connection to Circle+ node failed"""
3225

33-
pass
34-
3526

3627
class ProtocolError(PlugwiseException):
3728
"""Error while decode received data"""
3829

39-
pass
40-
4130

4231
class TimeoutException(PlugwiseException):
4332
"""Timeout expired while waiting for response from node"""
4433

45-
pass
46-
4734

4835
### Smile exceptions ###
4936

5037

51-
class PlugwiseError(Exception):
52-
"""Plugwise exceptions class."""
53-
54-
pass
55-
56-
57-
class ConnectionFailedError(PlugwiseError):
38+
class ConnectionFailedError(PlugwiseException):
5839
"""Raised when unable to connect."""
5940

60-
pass
61-
6241

63-
class InvalidAuthentication(PlugwiseError):
42+
class InvalidAuthentication(PlugwiseException):
6443
"""Raised when unable to authenticate."""
6544

66-
pass
67-
6845

69-
class UnsupportedDeviceError(PlugwiseError):
46+
class UnsupportedDeviceError(PlugwiseException):
7047
"""Raised when device is not supported."""
7148

72-
pass
7349

74-
75-
class DeviceSetupError(PlugwiseError):
50+
class DeviceSetupError(PlugwiseException):
7651
"""Raised when device is missing critical setup data."""
7752

78-
pass
79-
8053

81-
class DeviceTimeoutError(PlugwiseError):
54+
class DeviceTimeoutError(PlugwiseException):
8255
"""Raised when device is not supported."""
8356

84-
pass
8557

86-
87-
class ErrorSendingCommandError(PlugwiseError):
58+
class ErrorSendingCommandError(PlugwiseException):
8859
"""Raised when device is not accepting the command."""
8960

90-
pass
91-
9261

93-
class ResponseError(PlugwiseError):
62+
class ResponseError(PlugwiseException):
9463
"""Raised when empty or error in response returned."""
9564

96-
pass
97-
9865

99-
class InvalidXMLError(PlugwiseError):
66+
class InvalidXMLError(PlugwiseException):
10067
"""Raised when response holds incomplete or invalid XML data."""
10168

102-
pass
10369

104-
105-
class XMLDataMissingError(PlugwiseError):
70+
class XMLDataMissingError(PlugwiseException):
10671
"""Raised when xml data is empty."""
107-
108-
pass

plugwise/smile.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ async def _create_session() -> aiohttp.ClientSession:
105105

106106
async def connect(self):
107107
"""Connect to Plugwise device."""
108-
# pylint: disable=too-many-return-statements,raise-missing-from
109108
names = []
110109

111110
result = await self.request(DOMAIN_OBJECTS)
@@ -211,16 +210,9 @@ async def close_connection(self):
211210
await self.websession.close()
212211

213212
async def request(
214-
self,
215-
command,
216-
retry=3,
217-
method="get",
218-
data=None,
219-
headers=None,
213+
self, command, retry=3, method="get", data=None, headers=None,
220214
):
221215
"""Request data."""
222-
# pylint: disable=too-many-return-statements,raise-missing-from
223-
224216
resp = None
225217
url = f"{self._endpoint}{command}"
226218

plugwise/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ def int_to_uint(val, octals):
6565
val = val + (1 << bits)
6666
return val
6767

68+
6869
def escape_illegal_xml_characters(xmldata):
6970
"""Replace illegal &-characters."""
7071
return re.sub(r"&([^a-zA-Z#])", r"&amp;\1", xmldata)
7172

73+
7274
def format_measure(measure):
7375
"""Format measure to correct type."""
7476
try:
@@ -88,6 +90,7 @@ def format_measure(measure):
8890
measure = False
8991
return measure
9092

93+
9194
def determine_selected(available, selected, schemas):
9295
"""Determine selected schema from available schemas."""
9396
for schema_a, schema_b in schemas.items():
@@ -96,6 +99,7 @@ def determine_selected(available, selected, schemas):
9699
selected = schema_a
97100
return available, selected
98101

102+
99103
def in_between(now, start, end):
100104
"""Determine timing for schedules."""
101105
if start <= end:
@@ -267,9 +271,7 @@ def __init__(self, hour=0, minute=0, second=0):
267271
def deserialize(self, val):
268272
CompositeType.deserialize(self, val)
269273
self.value = datetime.time(
270-
int(self.hour.value),
271-
int(self.minute.value),
272-
int(self.second.value),
274+
int(self.hour.value), int(self.minute.value), int(self.second.value),
273275
)
274276

275277

0 commit comments

Comments
 (0)