zcc-helper 3.4.dev3__tar.gz → 3.4.dev5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {zcc_helper-3.4.dev3/zcc_helper.egg-info → zcc_helper-3.4.dev5}/PKG-INFO +1 -1
  2. zcc_helper-3.4.dev5/zcc/__init__.py +14 -0
  3. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/__main__.py +2 -1
  4. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/constants.py +1 -1
  5. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/discovery.py +17 -33
  6. zcc_helper-3.4.dev5/zcc/errors.py +16 -0
  7. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5/zcc_helper.egg-info}/PKG-INFO +1 -1
  8. zcc_helper-3.4.dev3/zcc/__init__.py +0 -10
  9. zcc_helper-3.4.dev3/zcc/errors.py +0 -5
  10. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/LICENSE.txt +0 -0
  11. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/README.md +0 -0
  12. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/setup.cfg +0 -0
  13. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/setup.py +0 -0
  14. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/tests/test_controller.py +0 -0
  15. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/tests/test_device.py +0 -0
  16. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/tests/test_server.py +0 -0
  17. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/tests/test_socket.py +0 -0
  18. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/controller.py +0 -0
  19. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/description.py +0 -0
  20. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/device.py +0 -0
  21. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/manufacture_info.py +0 -0
  22. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/protocol.py +0 -0
  23. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/socket.py +0 -0
  24. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/trace.py +0 -0
  25. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc/watchdog.py +0 -0
  26. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc.py +0 -0
  27. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc_helper.egg-info/SOURCES.txt +0 -0
  28. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc_helper.egg-info/dependency_links.txt +0 -0
  29. {zcc_helper-3.4.dev3 → zcc_helper-3.4.dev5}/zcc_helper.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zcc_helper
3
- Version: 3.4.dev3
3
+ Version: 3.4.dev5
4
4
  Summary: ZIMI ZCC helper module
5
5
  Author: Mark Hannon
6
6
  Author-email: mark.hannon@gmail.com
@@ -0,0 +1,14 @@
1
+ '''ZCC Support Library to support ZIMI based home network elements'''
2
+ import logging
3
+ import sys
4
+
5
+ from .controller import ControlPoint
6
+ from .description import ControlPointDescription
7
+ from .discovery import ControlPointDiscoveryService
8
+ from .errors import ( ControlPointError,
9
+ ControlPointConnectionRefusedError,
10
+ ControlPointCannotConnectError,
11
+ ControlPointInvalidHostError,
12
+ ControlPointTimeoutError)
13
+
14
+ logging.basicConfig(stream=sys.stderr)
@@ -100,9 +100,10 @@ async def main(args):
100
100
  return
101
101
 
102
102
  if options.test_connection and options.host and options.port:
103
- await ControlPointDiscoveryService(
103
+ result = await ControlPointDiscoveryService(
104
104
  verbosity=options.verbosity
105
105
  ).validate_connection(host=options.host, port=options.port)
106
+ print(result)
106
107
  return
107
108
 
108
109
  if options.host and options.port:
@@ -9,4 +9,4 @@ APP_ID = "ZvWqWJQB"
9
9
  APP_TOKEN = "3422ecbb-cf6a-404c-b3dc-2023dd213535"
10
10
 
11
11
  NAME = "zcc_helper"
12
- VERSION = "3.4-dev3"
12
+ VERSION = "3.4-dev5"
@@ -13,23 +13,13 @@ from typing import Tuple
13
13
  from zcc.constants import LEVEL_BY_VERBOSITY
14
14
  from zcc.controller import ControlPoint
15
15
  from zcc.description import ControlPointDescription
16
- from zcc.errors import ControlPointError
16
+ from zcc.errors import ( ControlPointError,
17
+ ControlPointConnectionRefusedError,
18
+ ControlPointCannotConnectError,
19
+ ControlPointInvalidHostError,
20
+ ControlPointTimeoutError)
17
21
  from zcc.protocol import ControlPointProtocol
18
22
 
19
-
20
- class ControlPointDiscoveryErrors(StrEnum):
21
- """Discovery errors."""
22
-
23
- ALREADY_CONFIGURED = "already_configured"
24
- CANNOT_CONNECT = "cannot_connect"
25
- CONNECTION_REFUSED = "connection_refused"
26
- DISCOVERY_FAILURE = "discovery_failure"
27
- INVALID_HOST = "invalid_host"
28
- INVALID_PORT = "invalid_port"
29
- TIMEOUT = "timeout"
30
- UNKNOWN = "unknown"
31
-
32
-
33
23
  class ControlPointDiscoveryProtocol(asyncio.DatagramProtocol):
34
24
  """Listens for ZCC announcements on the defined UDP port."""
35
25
 
@@ -154,14 +144,12 @@ class ControlPointDiscoveryService:
154
144
 
155
145
  async def validate_connection(
156
146
  self, host: str, port: int
157
- ) -> ControlPointDescription | dict[str, str]:
147
+ ) -> ControlPointDescription:
158
148
  """Validate ability to connect and close a connection.
159
149
 
160
- Return a ControlPointDescription if OK or error dictionary if not.
150
+ Returns ControlPointDescription if OK.
161
151
  """
162
152
 
163
- error = None
164
-
165
153
  try:
166
154
  socket.gethostbyname(host)
167
155
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -169,25 +157,21 @@ class ControlPointDiscoveryService:
169
157
  try:
170
158
  s.connect((host, port))
171
159
  s.close()
172
- except ConnectionRefusedError:
173
- error = {"error": ControlPointDiscoveryErrors.CONNECTION_REFUSED}
174
- except TimeoutError:
175
- error = {"error": ControlPointDiscoveryErrors.TIMEOUT}
176
- except socket.gaierror:
177
- error = {"error": ControlPointDiscoveryErrors.CANNOT_CONNECT}
178
- except socket.gaierror:
179
- error = {"error": ControlPointDiscoveryErrors.INVALID_HOST}
180
-
181
- if error:
182
- self.logger.error(error)
183
- return error
160
+ except ConnectionRefusedError as e:
161
+ raise ControlPointConnectionRefusedError() from e
162
+ except TimeoutError as e:
163
+ raise ControlPointTimeoutError() from e
164
+ except socket.gaierror as e:
165
+ raise ControlPointCannotConnectError() from e
166
+ except socket.gaierror as e:
167
+ raise ControlPointInvalidHostError() from e
184
168
 
185
169
  api = ControlPoint(ControlPointDescription(host=host, port=port))
186
170
 
187
171
  try:
188
172
  await api.connect(fast=True)
189
- except ControlPointError:
190
- return {"error": ControlPointDiscoveryErrors.CANNOT_CONNECT}
173
+ except ControlPointError as e:
174
+ raise ControlPointCannotConnectError() from e
191
175
 
192
176
  self.validation_result = ControlPointDescription(
193
177
  brand=api.brand,
@@ -0,0 +1,16 @@
1
+ '''ControlPoint error class'''
2
+
3
+
4
+ class ControlPointError(Exception):
5
+ '''Represents a ZCC controller error.'''
6
+
7
+ class ControlPointCannotConnectError(ControlPointError):
8
+ '''Represents a connect connect error when connecting to zcc.'''
9
+
10
+ class ControlPointInvalidHostError(ControlPointError):
11
+ '''Represents an invalid host error when connecting to zcc.'''
12
+ class ControlPointConnectionRefusedError(ControlPointError):
13
+ '''Represents a connection refused when connecting to zcc.'''
14
+
15
+ class ControlPointTimeoutError(ControlPointError):
16
+ '''Represents a connection timeout when connecting to zcc.'''
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zcc_helper
3
- Version: 3.4.dev3
3
+ Version: 3.4.dev5
4
4
  Summary: ZIMI ZCC helper module
5
5
  Author: Mark Hannon
6
6
  Author-email: mark.hannon@gmail.com
@@ -1,10 +0,0 @@
1
- '''ZCC Support Library to support ZIMI based home network elements'''
2
- import logging
3
- import sys
4
-
5
- from .controller import ControlPoint
6
- from .description import ControlPointDescription
7
- from .discovery import ControlPointDiscoveryService, ControlPointDiscoveryErrors
8
- from .errors import ControlPointError
9
-
10
- logging.basicConfig(stream=sys.stderr)
@@ -1,5 +0,0 @@
1
- '''ControlPoint error class'''
2
-
3
-
4
- class ControlPointError(Exception):
5
- '''Represents a ZCC controller error.'''
File without changes
File without changes
File without changes
File without changes
File without changes