weheat 2024.9.4rc2__py3-none-any.whl → 2024.9.10__py3-none-any.whl

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.

Potentially problematic release.


This version of weheat might be problematic. Click here for more details.

@@ -1,12 +1,18 @@
1
+ """Weheat heat pump abstraction from the API."""
1
2
  from enum import Enum, auto
2
3
  from weheat.configuration import Configuration
3
4
  from weheat.api_client import ApiClient
4
5
  from weheat.api.heat_pump_log_api import HeatPumpLogApi
6
+ from weheat.api.energy_log_api import EnergyLogApi
7
+ from datetime import datetime, timedelta
8
+
9
+ # before this date no energy logs are available, so start from this point onwards
10
+ START_DATE = datetime(2023, 1, 1, 0, 0, 0)
5
11
 
6
12
 
7
13
  class HeatPump:
14
+ """Heat pump class representing a heat pump."""
8
15
  class State(Enum):
9
- UNDEFINED = auto()
10
16
  STANDBY = auto()
11
17
  WATER_CHECK = auto()
12
18
  HEATING = auto()
@@ -21,8 +27,10 @@ class HeatPump:
21
27
  self._api_url = api_url
22
28
  self._uuid = uuid
23
29
  self._last_log = None
30
+ self._energy_consumption = None
24
31
 
25
32
  def get_status(self, access_token: str):
33
+ """Updates the heat pump instance with data from the API."""
26
34
  try:
27
35
  config = Configuration(host=self._api_url, access_token=access_token)
28
36
 
@@ -34,14 +42,33 @@ class HeatPump:
34
42
  )
35
43
  if response.status_code == 200:
36
44
  self._last_log = response.data
45
+
46
+ # Also get all energy totals form past years and add them together
47
+ # As end time pick today + 1 day to avoid issues with timezones
48
+ response = EnergyLogApi(client).api_v1_energy_logs_heat_pump_id_get_with_http_info(heat_pump_id=self._uuid,
49
+ start_time=START_DATE,
50
+ end_time=datetime.now() + timedelta(days=1),
51
+ interval='Year')
52
+
53
+ if response.status_code == 200:
54
+ # aggregate the energy consumption
55
+ self._energy_consumption = 0
56
+ for year in response.data:
57
+ self._energy_consumption += year.total_ein_cooling
58
+ self._energy_consumption += year.total_ein_heating
59
+ self._energy_consumption += year.total_ein_heating_defrost
60
+ self._energy_consumption += year.total_ein_dhw
61
+ self._energy_consumption += year.total_ein_dhw_defrost
62
+
63
+
64
+
37
65
  except Exception as e:
38
66
  self._last_log = None
67
+ self._energy_consumption = None
39
68
  raise e
40
69
 
41
- def _update_properties(self):
42
- pass
43
-
44
70
  def _if_available(self, key):
71
+ """Returns the value from the last logged value if available. None otherwise."""
45
72
  if self._last_log is not None and hasattr(self._last_log, key):
46
73
  return getattr(self._last_log, key)
47
74
  return None
@@ -54,48 +81,69 @@ class HeatPump:
54
81
 
55
82
  @property
56
83
  def water_inlet_temperature(self):
84
+ """The heat pump water inlet temperature."""
57
85
  return self._if_available("t_water_in")
58
86
 
59
87
  @property
60
88
  def water_outlet_temperature(self):
89
+ """The heat pump water outlet temperature."""
61
90
  return self._if_available("t_water_out")
62
91
 
63
92
  @property
64
93
  def water_house_in_temperature(self):
94
+ """The water house in temperature."""
65
95
  return self._if_available("t_water_house_in")
66
96
 
67
97
  @property
68
98
  def air_inlet_temperature(self):
99
+ """The heat pump air inlet temperature."""
69
100
  return self._if_available("t_air_in")
70
101
 
71
102
  @property
72
103
  def air_outlet_temperature(self):
104
+ """The heat pump air outlet temperature."""
73
105
  return self._if_available("t_air_out")
74
106
 
75
107
  @property
76
108
  def thermostat_water_setpoint(self):
109
+ """The thermostat water setpoint."""
77
110
  return self._if_available("t_thermostat_setpoint")
78
111
 
79
112
  @property
80
113
  def thermostat_room_temperature(self):
114
+ """The thermostat current room temperature."""
81
115
  return self._if_available("t_room")
82
116
 
83
117
  @property
84
118
  def thermostat_room_temperature_setpoint(self):
119
+ """The thermostat room temperature setpoint."""
85
120
  return self._if_available("t_room_target")
86
121
 
87
122
  @property
88
123
  def thermostat_on_off_state(self):
124
+ """The thermostat on/off state."""
89
125
  return self._if_available("on_off_thermostat_state")
90
126
 
91
127
  @property
92
128
  def power_input(self):
129
+ """The heat pumps power input."""
93
130
  return self._if_available("cm_mass_power_in")
94
131
 
95
132
  @property
96
133
  def power_output(self):
134
+ """The heat pumps hydraulic output power."""
97
135
  return self._if_available("cm_mass_power_out")
98
136
 
137
+ @property
138
+ def dhw_top_temperature(self):
139
+ """The DHW vessel top temperature."""
140
+ return self._if_available("t1")
141
+
142
+ @property
143
+ def dhw_bottom_temperature(self):
144
+ """The DHW vessel bottom temperature."""
145
+ return self._if_available("t2")
146
+
99
147
  @property
100
148
  def cop(self):
101
149
  """
@@ -110,25 +158,30 @@ class HeatPump:
110
158
 
111
159
  @property
112
160
  def inside_unit_water_pump_state(self):
161
+ """Decoded water pump state."""
113
162
  return self._if_available("control_bridge_status_decoded_water_pump")
114
163
 
115
164
  @property
116
165
  def inside_unit_auxilary_pump_state(self):
166
+ """Decoded auxilary pump state."""
117
167
  return self._if_available("control_bridge_status_decoded_water_pump2")
118
168
 
119
169
  @property
120
170
  def inside_unit_dhw_valve_or_pump_state(self):
171
+ """Decoded DHW valve or pump state."""
121
172
  return self._if_available("control_bridge_status_decoded_dhw_valve")
122
173
 
123
174
  @property
124
175
  def inside_unit_gas_boiler_state(self):
176
+ """Decoded gas boiler state."""
125
177
  return self._if_available("control_bridge_status_decoded_gas_boiler")
126
178
 
127
179
  @property
128
- def heat_pump_state(self) -> State:
180
+ def heat_pump_state(self) -> State | None:
181
+ """The heat pump state."""
129
182
  numeric_state = self._if_available("state")
130
183
  if numeric_state is None:
131
- return self.State.UNDEFINED
184
+ return None
132
185
 
133
186
  if numeric_state == 40:
134
187
  return self.State.STANDBY
@@ -146,5 +199,9 @@ class HeatPump:
146
199
  return self.State.MANUAL_CONTROL
147
200
  elif numeric_state == 200:
148
201
  return self.State.DEFROSTING
149
- else:
150
- return self.State.UNDEFINED
202
+ return None
203
+
204
+ @property
205
+ def energy_total(self):
206
+ """The total used energy in kWh from 2023 to now."""
207
+ return self._energy_consumption
@@ -3,7 +3,7 @@ from weheat.api_client import ApiClient
3
3
  from weheat.api.user_api import UserApi
4
4
 
5
5
 
6
- def get_user_id_from_token(api_url: str, access_token: str):
6
+ async def get_user_id_from_token(api_url: str, access_token: str):
7
7
  """ Get the user id from the current logged-in user. """
8
8
  try:
9
9
  config = Configuration(host=api_url, access_token=access_token)
@@ -11,8 +11,8 @@ def get_user_id_from_token(api_url: str, access_token: str):
11
11
  with ApiClient(configuration=config) as client:
12
12
  response = UserApi(
13
13
  client
14
- ).api_v1_users_me_get_with_http_info()
14
+ ).api_v1_users_me_get_with_http_info(async_req=True).get()
15
15
  if response.status_code == 200:
16
16
  return response.data.id
17
17
  except Exception as e:
18
- raise e
18
+ raise e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: weheat
3
- Version: 2024.9.4rc2
3
+ Version: 2024.9.10
4
4
  Summary: Weheat Backend client
5
5
  Home-page: https://github.com/wefabricate/wh-python
6
6
  Author: Jesper Raemaekers
@@ -8,8 +8,8 @@ weheat/rest.py,sha256=hLgJ0CYAR1Dr_LppodDNNC_chj5hEQUmzDmbxvID1ao,13808
8
8
  weheat/abstractions/__init__.py,sha256=cRdA_kyTIooo39I13_mqShSfZMqdzNGHbmrnITqgx6A,161
9
9
  weheat/abstractions/auth.py,sha256=VCAxJ4OIj7bsYttqJl5-juU0VUlSd3xPu7kUjtHZr3U,979
10
10
  weheat/abstractions/discovery.py,sha256=0HEXdtIuw3FIATUwX0xpeUVRnk8i-HRL21pE6b1mej0,1679
11
- weheat/abstractions/heat_pump.py,sha256=kzi6B6oQ8hFYzxMBZqVwbFRY16vR9OFnlWPErBQ_8uA,4649
12
- weheat/abstractions/user.py,sha256=9p5GZft1Q4qy1dF-6ZkGe_dZYLHvRvRBQhtzVoRjDVA,621
11
+ weheat/abstractions/heat_pump.py,sha256=RuUJJSGA2Zb8zg0HY-FbIQilIJQyCqTimthxcIgiN1Q,7469
12
+ weheat/abstractions/user.py,sha256=n1gmPaLKXmRjF1jDuMQ0951RkbBKm-Cx3cgUU2nOA9U,648
13
13
  weheat/api/__init__.py,sha256=DQnnRs5Z29Nf5sGdFd3f96xM6p_FMym-_-dvQC2VzdU,243
14
14
  weheat/api/energy_log_api.py,sha256=yIIqd-C_xHSM_1eNoj2i04IDkJkzU0-a9iFGDSd2zLo,11374
15
15
  weheat/api/heat_pump_api.py,sha256=FAf7jxosIAginCom-aUuFdj7jZupv8134OI6rpkdK80,24368
@@ -29,8 +29,8 @@ weheat/models/read_all_heat_pump_dto.py,sha256=PDaWb-2qSzAnMoIsNceHavT1ybIZa3-lv
29
29
  weheat/models/read_heat_pump_dto.py,sha256=ufDbcHxtB8o2jmk00bMP_xol3uCdoTOqiHS6UUzRic4,4514
30
30
  weheat/models/read_user_dto.py,sha256=J1YlL-WsXArbirllI1fHZrguKy5Wv35NIck59ICBSGg,3465
31
31
  weheat/models/role.py,sha256=eF6nawkz8mmCGQEmJx26Y2MPFmlKdpOOtJ2Q70b-Qtc,938
32
- weheat-2024.9.4rc2.dist-info/LICENSE,sha256=rWmFUq0uth2jpet-RQ2QPd2VhZkcPSUs6Dxfmbqkbis,1068
33
- weheat-2024.9.4rc2.dist-info/METADATA,sha256=-jCE8eL1LiKb158kj2xqkwpUCBZcpsdH_M29XFaILHc,3903
34
- weheat-2024.9.4rc2.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
35
- weheat-2024.9.4rc2.dist-info/top_level.txt,sha256=hLzdyvGZ9rs4AqK7U48mdHx_-FcP5sDuTSleDUvGAZw,7
36
- weheat-2024.9.4rc2.dist-info/RECORD,,
32
+ weheat-2024.9.10.dist-info/LICENSE,sha256=rWmFUq0uth2jpet-RQ2QPd2VhZkcPSUs6Dxfmbqkbis,1068
33
+ weheat-2024.9.10.dist-info/METADATA,sha256=7pvOua4tvtcqaL44AnNJ4RxKQdGAnORuq2LZKeafG1M,3901
34
+ weheat-2024.9.10.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
35
+ weheat-2024.9.10.dist-info/top_level.txt,sha256=hLzdyvGZ9rs4AqK7U48mdHx_-FcP5sDuTSleDUvGAZw,7
36
+ weheat-2024.9.10.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.1)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5