Skip to content

Commit 1168c13

Browse files
authored
Merge pull request #12 from eman/unitfix
unit conversion fix
2 parents 82f8f57 + 38125eb commit 1168c13

4 files changed

Lines changed: 255 additions & 6 deletions

File tree

docs/DEVICE_STATUS_FIELDS.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ This document lists the fields found in the ``status`` object of device status m
147147
- integer
148148
- °F
149149
- Target superheat value - the desired temperature difference ensuring complete refrigerant vaporization.
150-
- ``raw / 10.0``
150+
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
151151
* - ``compUse``
152152
- bool
153153
- None

docs/ENERGY_MONITORING.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,45 @@ Total upper electric heater runtime in minutes -
7979
``heater2RunningMinuteTotal`` (int): Total lower electric heater runtime
8080
in minutes
8181

82+
Historical Energy Usage
83+
-----------------------
84+
85+
Request detailed daily energy usage data for specific months:
86+
87+
.. code:: python
88+
89+
from nwp500 import NavienMqttClient, EnergyUsageResponse
90+
91+
def on_energy_usage(energy: EnergyUsageResponse):
92+
print(f"Total Usage: {energy.total.total_usage} Wh")
93+
print(f"Heat Pump: {energy.total.heat_pump_percentage:.1f}%")
94+
print(f"Electric: {energy.total.heat_element_percentage:.1f}%")
95+
96+
# Daily breakdown
97+
for day in energy.daily:
98+
print(f"Day {day.day}: {day.total_usage} Wh")
99+
100+
# Subscribe to energy usage responses
101+
await mqtt_client.subscribe_energy_usage(device, on_energy_usage)
102+
103+
# Request energy usage for September 2025
104+
await mqtt_client.request_energy_usage(device, year=2025, months=[9])
105+
106+
# Request multiple months
107+
await mqtt_client.request_energy_usage(device, year=2025, months=[7, 8, 9])
108+
109+
**Key Methods:**
110+
111+
- ``request_energy_usage(device, year, months)``: Request historical data
112+
- ``subscribe_energy_usage(device, callback)``: Subscribe to energy usage responses
113+
114+
**Response Fields:**
115+
116+
- ``total.total_usage`` (int): Total energy consumption in Wh
117+
- ``total.heat_pump_percentage`` (float): Percentage from heat pump
118+
- ``total.heat_element_percentage`` (float): Percentage from electric heaters
119+
- ``daily`` (list): Daily breakdown of usage per day
120+
82121
Energy Capacity
83122
---------------
84123

docs/MQTT_CLIENT.rst

Lines changed: 214 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,32 +396,128 @@ Publish a message to an MQTT topic.
396396
Device Command Methods
397397
^^^^^^^^^^^^^^^^^^^^^^
398398

399+
Complete MQTT API Reference
400+
''''''''''''''''''''''''''''
401+
402+
This section provides a comprehensive reference of all available MQTT client methods for requesting data and controlling devices.
403+
404+
**Request Methods & Corresponding Subscriptions**
405+
406+
+------------------------------------+---------------------------------------+----------------------------------------+
407+
| Request Method | Subscribe Method | Response Type |
408+
+====================================+=======================================+========================================+
409+
| ``request_device_status()`` | ``subscribe_device_status()`` | ``DeviceStatus`` object |
410+
+------------------------------------+---------------------------------------+----------------------------------------+
411+
| ``request_device_info()`` | ``subscribe_device_feature()`` | ``DeviceFeature`` object |
412+
+------------------------------------+---------------------------------------+----------------------------------------+
413+
| ``request_energy_usage()`` | ``subscribe_energy_usage()`` | ``EnergyUsageResponse`` object |
414+
+------------------------------------+---------------------------------------+----------------------------------------+
415+
| ``set_power()`` | ``subscribe_device_status()`` | Updated ``DeviceStatus`` |
416+
+------------------------------------+---------------------------------------+----------------------------------------+
417+
| ``set_dhw_mode()`` | ``subscribe_device_status()`` | Updated ``DeviceStatus`` |
418+
+------------------------------------+---------------------------------------+----------------------------------------+
419+
| ``set_dhw_temperature()`` | ``subscribe_device_status()`` | Updated ``DeviceStatus`` |
420+
+------------------------------------+---------------------------------------+----------------------------------------+
421+
| ``set_dhw_temperature_display()`` | ``subscribe_device_status()`` | Updated ``DeviceStatus`` |
422+
+------------------------------------+---------------------------------------+----------------------------------------+
423+
424+
**Generic Subscriptions**
425+
426+
+------------------------------------+---------------------------------------+----------------------------------------+
427+
| Method | Purpose | Response Type |
428+
+====================================+=======================================+========================================+
429+
| ``subscribe_device()`` | Subscribe to all device messages | Raw ``dict`` (all message types) |
430+
+------------------------------------+---------------------------------------+----------------------------------------+
431+
| ``subscribe()`` | Subscribe to any MQTT topic | Raw ``dict`` |
432+
+------------------------------------+---------------------------------------+----------------------------------------+
433+
399434
request_device_status()
400435
'''''''''''''''''''''''
401436

402437
.. code:: python
403438
404439
await mqtt_client.request_device_status(device: Device) -> int
405440
406-
Request current device status.
441+
Request current device status including temperatures, operation mode, power consumption, and error codes.
407442

408443
**Command:** ``16777219``
409444

410445
**Topic:** ``cmd/{device_type}/navilink-{device_id}/st``
411446

447+
**Response:** Subscribe with ``subscribe_device_status()`` to receive ``DeviceStatus`` objects
448+
449+
**Example:**
450+
451+
.. code:: python
452+
453+
def on_status(status: DeviceStatus):
454+
print(f"Water Temp: {status.dhwTemperature}°F")
455+
print(f"Mode: {status.operationMode}")
456+
print(f"Power: {status.currentInstPower}W")
457+
458+
await mqtt_client.subscribe_device_status(device, on_status)
459+
await mqtt_client.request_device_status(device)
460+
412461
request_device_info()
413462
'''''''''''''''''''''
414463

415464
.. code:: python
416465
417466
await mqtt_client.request_device_info(device: Device) -> int
418467
419-
Request device information.
468+
Request device information including firmware version, serial number, temperature limits, and capabilities.
420469

421470
**Command:** ``16777217``
422471

423472
**Topic:** ``cmd/{device_type}/navilink-{device_id}/st/did``
424473

474+
**Response:** Subscribe with ``subscribe_device_feature()`` to receive ``DeviceFeature`` objects
475+
476+
**Example:**
477+
478+
.. code:: python
479+
480+
def on_feature(feature: DeviceFeature):
481+
print(f"Firmware: {feature.controllerSwVersion}")
482+
print(f"Serial: {feature.controllerSerialNumber}")
483+
print(f"Temp Range: {feature.dhwTemperatureMin}-{feature.dhwTemperatureMax}°F")
484+
485+
await mqtt_client.subscribe_device_feature(device, on_feature)
486+
await mqtt_client.request_device_info(device)
487+
488+
request_energy_usage()
489+
''''''''''''''''''''''
490+
491+
.. code:: python
492+
493+
await mqtt_client.request_energy_usage(device: Device, year: int, months: list[int]) -> int
494+
495+
Request historical daily energy usage data for specified month(s). Returns heat pump and electric heating element consumption with daily breakdown.
496+
497+
**Command:** ``16777225``
498+
499+
**Topic:** ``cmd/{device_type}/navilink-{device_id}/st/energy-usage-daily-query/rd``
500+
501+
**Response:** Subscribe with ``subscribe_energy_usage()`` to receive ``EnergyUsageResponse`` objects
502+
503+
**Parameters:**
504+
505+
- ``year``: Year to query (e.g., 2025)
506+
- ``months``: List of months to query (1-12). Can request multiple months.
507+
508+
**Example:**
509+
510+
.. code:: python
511+
512+
def on_energy(energy: EnergyUsageResponse):
513+
print(f"Total Usage: {energy.total.total_usage} Wh")
514+
print(f"Heat Pump: {energy.total.heat_pump_percentage:.1f}%")
515+
for day in energy.daily:
516+
print(f"Day {day.day}: {day.total_usage} Wh")
517+
518+
await mqtt_client.subscribe_energy_usage(device, on_energy)
519+
await mqtt_client.request_energy_usage(device, year=2025, months=[9])
520+
425521
set_power()
426522
'''''''''''
427523

@@ -435,6 +531,8 @@ Turn device on or off.
435531

436532
**Mode:** ``power-on`` or ``power-off``
437533

534+
**Response:** Device status is updated; subscribe with ``subscribe_device_status()`` to see changes
535+
438536
set_dhw_mode()
439537
''''''''''''''
440538

@@ -456,6 +554,8 @@ Set DHW (Domestic Hot Water) operation mode. This sets the ``dhwOperationSetting
456554
* ``4``: High Demand (faster recovery - Hybrid: Boost)
457555
* ``5``: Vacation (suspend heating for 0-99 days)
458556

557+
**Response:** Device status is updated; subscribe with ``subscribe_device_status()`` to see changes
558+
459559
**Important:** Setting the mode updates ``dhwOperationSetting`` but does not immediately change ``operationMode``. The ``operationMode`` field reflects the device's current operational state and changes automatically when the device starts/stops heating. See :doc:`DEVICE_STATUS_FIELDS` for details on the relationship between these fields.
460560

461561
set_dhw_temperature()
@@ -465,13 +565,44 @@ set_dhw_temperature()
465565
466566
await mqtt_client.set_dhw_temperature(device: Device, temperature: int) -> int
467567
468-
Set DHW target temperature.
568+
Set DHW target temperature using the **MESSAGE value** (20°F lower than display).
469569

470570
**Command:** ``33554433``
471571

472572
**Mode:** ``dhw-temperature``
473573

474-
**Parameters:** - ``temperature``: Target temperature in Fahrenheit
574+
**Parameters:**
575+
576+
- ``temperature``: Target temperature in Fahrenheit (message value, not display value)
577+
578+
**Response:** Device status is updated; subscribe with ``subscribe_device_status()`` to see changes
579+
580+
**Important:** The temperature in the message is 20°F lower than what displays on the device/app:
581+
582+
- Message value 120°F → Display shows 140°F
583+
- Message value 130°F → Display shows 150°F
584+
585+
set_dhw_temperature_display()
586+
''''''''''''''''''''''''''''''
587+
588+
.. code:: python
589+
590+
await mqtt_client.set_dhw_temperature_display(device: Device, display_temperature: int) -> int
591+
592+
Set DHW target temperature using the **DISPLAY value** (what you see on device/app). This is a convenience method that automatically converts display temperature to message value.
593+
594+
**Parameters:**
595+
596+
- ``display_temperature``: Target temperature as shown on display/app (Fahrenheit)
597+
598+
**Response:** Device status is updated; subscribe with ``subscribe_device_status()`` to see changes
599+
600+
**Example:**
601+
602+
.. code:: python
603+
604+
# Set display temperature to 140°F (sends 120°F in message)
605+
await mqtt_client.set_dhw_temperature_display(device, 140)
475606
476607
signal_app_connection()
477608
'''''''''''''''''''''''
@@ -484,6 +615,85 @@ Signal that the app has connected.
484615

485616
**Topic:** ``evt/{device_type}/navilink-{device_id}/app-connection``
486617

618+
Subscription Methods
619+
''''''''''''''''''''
620+
621+
subscribe_device_status()
622+
.........................
623+
624+
.. code:: python
625+
626+
await mqtt_client.subscribe_device_status(
627+
device: Device,
628+
callback: Callable[[DeviceStatus], None]
629+
) -> int
630+
631+
Subscribe to device status messages with automatic parsing into ``DeviceStatus`` objects. Use this after calling ``request_device_status()`` or any control commands to receive updates.
632+
633+
**Emits Events:**
634+
635+
- ``status_received``: Every status update (DeviceStatus)
636+
- ``temperature_changed``: Temperature changed (old_temp, new_temp)
637+
- ``mode_changed``: Operation mode changed (old_mode, new_mode)
638+
- ``power_changed``: Power consumption changed (old_power, new_power)
639+
- ``heating_started``: Device started heating (status)
640+
- ``heating_stopped``: Device stopped heating (status)
641+
- ``error_detected``: Error code detected (error_code, status)
642+
- ``error_cleared``: Error code cleared (error_code)
643+
644+
subscribe_device_feature()
645+
..........................
646+
647+
.. code:: python
648+
649+
await mqtt_client.subscribe_device_feature(
650+
device: Device,
651+
callback: Callable[[DeviceFeature], None]
652+
) -> int
653+
654+
Subscribe to device feature/info messages with automatic parsing into ``DeviceFeature`` objects. Use this after calling ``request_device_info()`` to receive device capabilities and firmware info.
655+
656+
**Emits Events:**
657+
658+
- ``feature_received``: Feature/info received (DeviceFeature)
659+
660+
subscribe_energy_usage()
661+
........................
662+
663+
.. code:: python
664+
665+
await mqtt_client.subscribe_energy_usage(
666+
device: Device,
667+
callback: Callable[[EnergyUsageResponse], None]
668+
) -> int
669+
670+
Subscribe to energy usage query responses with automatic parsing into ``EnergyUsageResponse`` objects. Use this after calling ``request_energy_usage()`` to receive historical energy data.
671+
672+
subscribe_device()
673+
..................
674+
675+
.. code:: python
676+
677+
await mqtt_client.subscribe_device(
678+
device: Device,
679+
callback: Callable[[str, dict], None]
680+
) -> int
681+
682+
Subscribe to all messages from a device (no parsing). Receives all message types as raw dictionaries. Use the specific subscription methods above for automatic parsing.
683+
684+
subscribe()
685+
...........
686+
687+
.. code:: python
688+
689+
await mqtt_client.subscribe(
690+
topic: str,
691+
callback: Callable[[str, dict], None],
692+
qos: mqtt.QoS = mqtt.QoS.AT_LEAST_ONCE
693+
) -> int
694+
695+
Subscribe to any MQTT topic. Supports wildcards (``#``, ``+``). Receives raw dictionary messages.
696+
487697
Periodic Request Methods (Optional)
488698
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
489699

src/nwp500/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ def from_dict(cls, data: dict):
380380

381381
# Convert fields with 'raw / 10.0' formula (non-temperature fields)
382382
div_10_fields = [
383-
"targetSuperHeat",
384383
"currentInletTemperature",
385384
"currentDhwFlowRate",
386385
"hpUpperOnDiffTempSetting",
@@ -414,6 +413,7 @@ def from_dict(cls, data: dict):
414413
"evaporatorTemperature",
415414
"ambientTemperature",
416415
"currentSuperHeat",
416+
"targetSuperHeat",
417417
]
418418
for field_name in heat_pump_temp_fields:
419419
if field_name in converted_data:

0 commit comments

Comments
 (0)