python-homewizard-energy 8.0.0a3__tar.gz → 8.0.0a4__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 (15) hide show
  1. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/PKG-INFO +1 -1
  2. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/homewizard_energy.py +4 -6
  3. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/models.py +31 -10
  4. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v1/__init__.py +13 -46
  5. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/__init__.py +6 -1
  6. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/pyproject.toml +1 -1
  7. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/LICENSE +0 -0
  8. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/README.md +0 -0
  9. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/__init__.py +0 -0
  10. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/const.py +0 -0
  11. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/errors.py +0 -0
  12. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/py.typed +0 -0
  13. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v1/const.py +0 -0
  14. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/cacert.py +0 -0
  15. {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/const.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-homewizard-energy
3
- Version: 8.0.0a3
3
+ Version: 8.0.0a4
4
4
  Summary: Asynchronous Python client for the HomeWizard Energy
5
5
  Home-page: https://github.com/homewizard/python-homewizard-energy
6
6
  License: Apache-2.0
@@ -59,20 +59,18 @@ class HomeWizardEnergy:
59
59
  except (UnsupportedError, NotImplementedError):
60
60
  return None
61
61
 
62
- if self._device is None:
63
- self._device = await fetch_data(self.device())
64
-
65
- measurement, system, state = await asyncio.gather(
62
+ device, measurement, system, state = await asyncio.gather(
63
+ fetch_data(self.device()),
66
64
  fetch_data(self.measurement()),
67
65
  fetch_data(self.system()),
68
66
  fetch_data(self.state()),
69
67
  )
70
68
 
71
69
  return CombinedModels(
72
- device=self._device, measurement=measurement, system=system, state=state
70
+ device=device, measurement=measurement, system=system, state=state
73
71
  )
74
72
 
75
- async def device(self) -> Device:
73
+ async def device(self, reset_cache: bool = False) -> Device:
76
74
  """Get the device information."""
77
75
  raise NotImplementedError
78
76
 
@@ -47,6 +47,31 @@ class CombinedModels:
47
47
  state: State | None
48
48
  system: System | None
49
49
 
50
+ def __init__(
51
+ self,
52
+ device: Device,
53
+ measurement: Measurement,
54
+ state: State | None,
55
+ system: System | None,
56
+ ):
57
+ self.device = device
58
+ self.measurement = measurement
59
+ self.state = state
60
+ self.system = system
61
+
62
+ # Move things around for backwards compatibility
63
+ ## measurement.wifi_ssid -> system.wifi_ssid
64
+ if self.measurement is not None and self.measurement.wifi_ssid is not None:
65
+ if self.system is None:
66
+ self.system = System()
67
+ self.system.wifi_ssid = self.measurement.wifi_ssid
68
+
69
+ ## state.brightness -> system.status_led_brightness_pct
70
+ if self.state is not None and self.state.brightness is not None:
71
+ if self.system is None:
72
+ self.system = System()
73
+ self.system.status_led_brightness_pct = (self.state.brightness / 255) * 100
74
+
50
75
 
51
76
  def get_verification_hostname(model: str, serial_number: str) -> str:
52
77
  """Helper method to convert device model and serial to identifier
@@ -320,7 +345,7 @@ class Measurement(BaseModel):
320
345
  return rv
321
346
 
322
347
  @staticmethod
323
- def to_datetime(timestamp: str | int | None) -> datetime | None:
348
+ def to_datetime(timestamp: str | int) -> datetime:
324
349
  """Convert DSRM gas-timestamp to datetime object.
325
350
 
326
351
  Args:
@@ -329,10 +354,6 @@ class Measurement(BaseModel):
329
354
  Returns:
330
355
  A datetime object.
331
356
  """
332
-
333
- if timestamp is None:
334
- return None
335
-
336
357
  if isinstance(timestamp, int):
337
358
  # V1 API uses int for timestamp
338
359
  return datetime.strptime(str(timestamp), "%y%m%d%H%M%S")
@@ -424,7 +445,7 @@ class Measurement(BaseModel):
424
445
  return d
425
446
 
426
447
 
427
- @dataclass
448
+ @dataclass(kw_only=True)
428
449
  class ExternalDevice(BaseModel):
429
450
  """Represents externally connected device."""
430
451
 
@@ -438,7 +459,7 @@ class ExternalDevice(BaseModel):
438
459
  INLET_HEAT_METER = "inlet_heat_meter"
439
460
 
440
461
  unique_id: datetime = field(
441
- default=None, metadata={"deserialize": lambda x: Measurement.hex_to_readable(x)}
462
+ metadata={"deserialize": lambda x: Measurement.hex_to_readable(x)}
442
463
  )
443
464
 
444
465
  type: DeviceType | None = field(
@@ -449,10 +470,10 @@ class ExternalDevice(BaseModel):
449
470
  else None
450
471
  },
451
472
  )
452
- value: float = field(default=0.0)
453
- unit: str = field(default="")
473
+ value: float = field()
474
+ unit: str = field()
454
475
  timestamp: datetime = field(
455
- default=None, metadata={"deserialize": lambda x: Measurement.to_datetime(x)}
476
+ metadata={"deserialize": lambda x: Measurement.to_datetime(x)}
456
477
  )
457
478
 
458
479
 
@@ -15,15 +15,7 @@ from aiohttp.hdrs import METH_GET, METH_PUT
15
15
  from ..const import LOGGER
16
16
  from ..errors import DisabledError, NotFoundError, RequestError, UnsupportedError
17
17
  from ..homewizard_energy import HomeWizardEnergy
18
- from ..models import (
19
- CombinedModels,
20
- Device,
21
- Measurement,
22
- State,
23
- StateUpdate,
24
- System,
25
- SystemUpdate,
26
- )
18
+ from ..models import Device, Measurement, State, StateUpdate, System, SystemUpdate
27
19
 
28
20
  T = TypeVar("T")
29
21
 
@@ -46,33 +38,17 @@ def optional_method(
46
38
  class HomeWizardEnergyV1(HomeWizardEnergy):
47
39
  """Communicate with a HomeWizard Energy device."""
48
40
 
49
- async def combined(self) -> CombinedModels:
50
- """Get all information."""
51
-
52
- models: CombinedModels = await super().combined()
53
-
54
- # Move things around for backwards compatibility
55
- ## measurement.wifi_ssid -> system.wifi_ssid
56
- if models.measurement is not None and models.measurement.wifi_ssid is not None:
57
- if models.system is None:
58
- models.system = System()
59
- models.system.wifi_ssid = models.measurement.wifi_ssid
60
-
61
- ## state.brightness -> system.status_led_brightness_pct
62
- if models.state is not None and models.state.brightness is not None:
63
- if models.system is None:
64
- models.system = System()
65
- models.system.status_led_brightness_pct = (
66
- models.state.brightness / 255
67
- ) * 100
41
+ async def device(self, reset_cache: bool = False) -> Device:
42
+ """Return the device object."""
68
43
 
69
- return models
44
+ if self._device is not None and not reset_cache:
45
+ return self._device
70
46
 
71
- async def device(self) -> Device:
72
- """Return the device object."""
73
47
  _, response = await self._request("api")
74
48
  device = Device.from_json(response)
75
49
 
50
+ # Cache device object
51
+ self._device = device
76
52
  return device
77
53
 
78
54
  async def measurement(self) -> Measurement:
@@ -101,15 +77,12 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
101
77
  if cloud_enabled is not None:
102
78
  # Executing the update
103
79
  data = SystemUpdate(cloud_enabled=cloud_enabled).to_dict()
104
- status, response = await self._request(
80
+ _, response = await self._request(
105
81
  "api/v1/system", method=METH_PUT, data=data
106
82
  )
107
83
 
108
84
  else:
109
- status, response = await self._request("api/v1/system")
110
-
111
- if status != HTTPStatus.OK:
112
- raise RequestError("Failed to get/set system")
85
+ _, response = await self._request("api/v1/system")
113
86
 
114
87
  system = System.from_json(response)
115
88
  return system
@@ -123,22 +96,19 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
123
96
  ) -> State:
124
97
  """Return or update the state object."""
125
98
 
126
- if self._device is not None and self._device.supports_state is False:
99
+ if self._device is not None and self._device.supports_state() is False:
127
100
  raise UnsupportedError("State is not supported")
128
101
 
129
102
  if power_on is not None or switch_lock is not None or brightness is not None:
130
103
  data = StateUpdate(
131
104
  power_on=power_on, switch_lock=switch_lock, brightness=brightness
132
105
  ).to_dict()
133
- status, response = await self._request(
106
+ _, response = await self._request(
134
107
  "api/v1/state", method=METH_PUT, data=data
135
108
  )
136
109
 
137
110
  else:
138
- status, response = await self._request("api/v1/state")
139
-
140
- if status != HTTPStatus.OK:
141
- raise RequestError("Failed to get/set state")
111
+ _, response = await self._request("api/v1/state")
142
112
 
143
113
  state = State.from_json(response)
144
114
  return state
@@ -149,7 +119,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
149
119
  ) -> bool:
150
120
  """Send identify request."""
151
121
 
152
- if self._device is not None and self._device.supports_state is False:
122
+ if self._device is not None and self._device.supports_identify() is False:
153
123
  raise UnsupportedError("State is not supported")
154
124
 
155
125
  await self._request("api/v1/identify", method=METH_PUT)
@@ -194,9 +164,6 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
194
164
  raise DisabledError(
195
165
  "API disabled. API must be enabled in HomeWizard Energy app"
196
166
  )
197
- case HTTPStatus.NO_CONTENT:
198
- # No content, just return
199
- return (HTTPStatus.NO_CONTENT, None)
200
167
  case HTTPStatus.NOT_FOUND:
201
168
  raise NotFoundError("Resource not found")
202
169
  case HTTPStatus.OK:
@@ -72,11 +72,16 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
72
72
  self._token = token
73
73
 
74
74
  @authorized_method
75
- async def device(self) -> Device:
75
+ async def device(self, reset_cache: bool = False) -> Device:
76
76
  """Return the device object."""
77
+ if self._device is not None and not reset_cache:
78
+ return self._device
79
+
77
80
  _, response = await self._request("/api")
78
81
  device = Device.from_json(response)
79
82
 
83
+ # Cache device object
84
+ self._device = device
80
85
  return device
81
86
 
82
87
  @authorized_method
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-homewizard-energy"
3
- version = "8.0.0-alpha-3"
3
+ version = "8.0.0-alpha-4"
4
4
  description = "Asynchronous Python client for the HomeWizard Energy"
5
5
  authors = ["DCSBL"]
6
6
  maintainers = ["DCSBL"]