aioccl 2024.12.3__tar.gz → 2024.12.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioccl
3
- Version: 2024.12.3
3
+ Version: 2024.12.6
4
4
  Summary: A Python library for CCL API server
5
5
  Home-page: https://github.com/fkiscd/aioccl
6
6
  Download-URL: https://github.com/fkiscd/aioccl
@@ -16,21 +16,22 @@ CCL_DEVICE_INFO_TYPES = ("serial_no", "mac_address", "model", "fw_ver")
16
16
  class CCLDevice:
17
17
  """Mapping for a CCL device."""
18
18
  _binary_sensors: dict[str, CCLSensor] | None = {}
19
- _fw_ver: str | None
20
- _last_updated_time: float | None
21
- _mac_address: str | None
22
- _model: str | None
19
+ _device_id: str | None = None
20
+ _fw_ver: str | None = None
21
+ _last_updated_time: float | None = None
22
+ _mac_address: str | None = None
23
+ _model: str | None = None
23
24
  _new_binary_sensor_callbacks = set()
24
25
  _new_sensors: list[CCLSensor] | None = []
25
26
  _new_sensor_callbacks = set()
27
+ _passkey = ''
26
28
  _sensors: dict[str, CCLSensor] | None = {}
27
- _serial_no: str | None
29
+ _serial_no: str | None = None
28
30
  _update_callbacks = set()
29
31
 
30
32
 
31
33
  def __init__(self, passkey: str):
32
34
  """Initialize a CCL device."""
33
- _LOGGER.debug("Initializing CCL Device: %s", self)
34
35
  self._passkey = passkey
35
36
 
36
37
  @property
@@ -41,12 +42,18 @@ class CCLDevice:
41
42
  @property
42
43
  def device_id(self) -> str | None:
43
44
  """Return the device ID."""
44
- return self._mac_address.replace(":", "").lower()[-6:]
45
+ try:
46
+ self._device_id = self._mac_address.replace(":", "").lower()[-6:]
47
+ except Exception: # pylint: disable=broad-exception-caught
48
+ return None
49
+ return self._device_id
45
50
 
46
51
  @property
47
52
  def name(self) -> str | None:
48
53
  """Return the display name."""
49
- return self._model + " - " + self.device_id
54
+ if self._device_id is not None:
55
+ return self._model + " - " + self._device_id
56
+ return self._model
50
57
 
51
58
  @property
52
59
  def mac_address(self) -> str | None:
@@ -133,7 +140,6 @@ class CCLDevice:
133
140
  """Schedule call all registered callbacks."""
134
141
  for sensor in self._new_sensors[:]:
135
142
  try:
136
- _LOGGER.debug("Publishing new sensor: %s", sensor)
137
143
  if sensor.binary:
138
144
  for callback in self._new_binary_sensor_callbacks:
139
145
  callback(sensor)
@@ -13,7 +13,7 @@ class CCLSensor:
13
13
  """Initialize a CCL sensor."""
14
14
  self._value: None | str | int | float = None
15
15
 
16
- if key in CCL_SENSORS.keys():
16
+ if key in CCL_SENSORS:
17
17
  self._key = key
18
18
 
19
19
  @property
@@ -34,8 +34,9 @@ class CCLSensor:
34
34
  @property
35
35
  def compartment(self) -> None | str:
36
36
  """Decide which compartment it belongs to."""
37
- if CCL_SENSORS[self._key].compartment is not None:
37
+ if isinstance(CCL_SENSORS[self._key].compartment, CCLDeviceCompartment):
38
38
  return CCL_SENSORS[self._key].compartment.value
39
+ return None
39
40
 
40
41
  @property
41
42
  def binary(self) -> bool:
@@ -47,13 +48,12 @@ class CCLSensor:
47
48
  """Return the intrinsic sensor value."""
48
49
  if self.sensor_type.name in CCL_SENSOR_VALUES:
49
50
  return CCL_SENSOR_VALUES[self.sensor_type.name].get(self._value)
50
- elif self.sensor_type == CCLSensorTypes.BATTERY_BINARY:
51
+ if self.sensor_type == CCLSensorTypes.BATTERY_BINARY:
51
52
  try:
52
53
  return int(self._value) - 1
53
54
  except ValueError:
54
55
  pass
55
- else:
56
- return self._value
56
+ return self._value
57
57
 
58
58
  @value.setter
59
59
  def value(self, new_value):
@@ -66,7 +66,7 @@ class CCLSensorPreset:
66
66
 
67
67
  name: str
68
68
  sensor_type: str
69
- compartment: None | CCLDeviceCompartment = None
69
+ compartment: CCLDeviceCompartment | None = None
70
70
  binary: bool = False
71
71
 
72
72
 
@@ -3,7 +3,6 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
- from typing import Callable
7
6
 
8
7
  from aiohttp import web
9
8
 
@@ -25,14 +24,9 @@ class CCLServer:
25
24
  """Register a device with a passkey."""
26
25
  CCLServer.devices.setdefault(device.passkey, device)
27
26
  _LOGGER.debug("Device registered: %s", device)
28
-
29
- @staticmethod
30
- def get_handler() -> Callable[[web.BaseRequest], web.Response]:
31
- """Get the handler."""
32
- return CCLServer._handler
33
27
 
34
28
  @staticmethod
35
- async def _handler(request: web.BaseRequest) -> web.Response:
29
+ async def handler(request: web.BaseRequest | web.Request) -> web.Response:
36
30
  """Handle POST requests for data updating."""
37
31
  _body: dict[str, None | str | int | float] = {}
38
32
  _device: CCLDevice = None
@@ -43,12 +37,12 @@ class CCLServer:
43
37
  _text: None | str = None
44
38
 
45
39
  try:
40
+ _passkey = request.path[-8:]
46
41
  for passkey in CCLServer.devices:
47
- if passkey == request.match_info["passkey"]:
48
- _passkey = passkey
42
+ if passkey == _passkey:
43
+ _device = CCLServer.devices[_passkey]
49
44
  break
50
- _device = CCLServer.devices[_passkey]
51
- assert _device, 404
45
+ assert isinstance(_device, CCLDevice), 404
52
46
 
53
47
  assert request.content_type == "application/json", 400
54
48
  assert 0 < request.content_length <= 5000, 400
@@ -82,7 +76,7 @@ class CCLServer:
82
76
  return web.Response(status=_status, text=_text)
83
77
 
84
78
  app = web.Application()
85
- app.add_routes([web.get('/{passkey}', _handler)])
79
+ app.add_routes([web.get('/{passkey}', handler)])
86
80
  runner = web.AppRunner(app)
87
81
 
88
82
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioccl
3
- Version: 2024.12.3
3
+ Version: 2024.12.6
4
4
  Summary: A Python library for CCL API server
5
5
  Home-page: https://github.com/fkiscd/aioccl
6
6
  Download-URL: https://github.com/fkiscd/aioccl
@@ -3,7 +3,7 @@
3
3
  from pathlib import Path
4
4
  from setuptools import find_packages, setup
5
5
 
6
- VERSION = "2024.12.3"
6
+ VERSION = "2024.12.6"
7
7
 
8
8
  ROOT_DIR = Path(__file__).parent.resolve()
9
9
 
File without changes
File without changes
File without changes