Skip to content

Commit

Permalink
Support multiple api versions (#23)
Browse files Browse the repository at this point in the history
* support multiple api versions
* provide usage example for versions
  • Loading branch information
LavermanJJ committed Feb 27, 2023
1 parent bef1011 commit d6bda6c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

This integration has been tested with Solarfocus eco<sup>manager-touch</sup> version `21.040`.

Added biomass boiler pellet statistics (available since version 23.010)
Added biomass boiler pellet statistics (available since version 23.010). To have them available, choose the respective API version when instantiating the client:

```python
solarfocus = SolarfocusAPI(ip="[Your-IP]", system=Systems.Vampair, api_version=ApiVersions.V_23_010)
```

### Systems

Expand Down
14 changes: 8 additions & 6 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pysolarfocus import SolarfocusAPI,Systems
from pysolarfocus import SolarfocusAPI,Systems,ApiVersions

# Create the Solarfocus API client
# TODO: Adapt IP-Address
solarfocus = SolarfocusAPI(ip="IP-Address", system=Systems.Therminator)
# TODO: Choose either Vampair or Therminator and adapt IP-Address and version
solarfocus = SolarfocusAPI(ip="IP-Address", system=Systems.Vampair, api_version=ApiVersions.V_21_140)

solarfocus.connect()
# Fetch the values
solarfocus.update()
Expand All @@ -14,9 +15,10 @@
print("\n")
print(solarfocus.buffers[0])
print("\n")
print(solarfocus.pelletsboiler)
print("\n")
print(solarfocus.heatpump)
if solarfocus.system is Systems.Therminator:
print(solarfocus.pelletsboiler)
if solarfocus.system is Systems.Vampair:
print(solarfocus.heatpump)
print("\n")
print(solarfocus.photovoltaic)
print("\n")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pysolarfocus"
version = "3.4.0"
version = "3.5.0"
description = "Unofficial, local Solarfocus client"
authors = ["Jeroen Laverman <jjlaverman@web.de>"]
license = "Apache-2.0"
Expand Down
19 changes: 15 additions & 4 deletions pysolarfocus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Python client lib for Solarfocus"""
__version__ = "3.4.0"
__version__ = "3.5.0"

from enum import Enum
from packaging import version

#Default port for modbus
PORT = 502
Expand All @@ -14,6 +15,10 @@ class Systems(str, Enum):
Vampair = "Vampair"
Therminator = "Therminator"

class ApiVersions(Enum):
V_21_140 = version.parse("21.140")
V_23_010 = version.parse("23.010")

from .modbus_wrapper import ModbusConnector
from .component_factory import ComponentFactory
from .const import SLAVE_ID
Expand All @@ -22,17 +27,22 @@ class SolarfocusAPI:
"""Solarfocus Heating System"""

@property
def system(self):
def system(self) -> Systems:
return self._system

@property
def api_version(self) -> ApiVersions:
return self._api_version

def __init__(self,
ip:str,
heating_circuit_count:int = 1,
buffer_count:int = 1,
boiler_count:int = 1,
system:Systems=Systems.Vampair,
port:int=PORT,
slave_id:int=SLAVE_ID):
slave_id:int=SLAVE_ID,
api_version:ApiVersions=ApiVersions.V_21_140):
"""Initialize Solarfocus communication."""
assert heating_circuit_count >= 0 and heating_circuit_count < 9, "Heating circuit count must be between 0 and 8"
assert buffer_count >= 0 and buffer_count < 5, "Buffer count must be between 0 and 4"
Expand All @@ -47,10 +57,11 @@ def __init__(self,
#Single components
self.heatpump = self.__factory.heatpump(system)
self.photovoltaic = self.__factory.photovoltaic(system)
self.pelletsboiler = self.__factory.pelletsboiler(system)
self.pelletsboiler = self.__factory.pelletsboiler(system,api_version)
self.solar = self.__factory.solar(system)
self._slave_id = slave_id
self._system = system
self._api_version = api_version

def connect(self):
"""Connect to Solarfocus eco manager-touch"""
Expand Down
6 changes: 3 additions & 3 deletions pysolarfocus/component_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .components.photovoltaic import *
from .components.solar import *
from .modbus_wrapper import ModbusConnector
from . import Systems
from . import Systems, ApiVersions


class ComponentFactory:
Expand Down Expand Up @@ -53,8 +53,8 @@ def heatpump(self, system:Systems)->HeatPump:
def photovoltaic(self, system:Systems)->Photovoltaic:
return Photovoltaic()._initialize(self.__modbus_connector)

def pelletsboiler(self, system:Systems)->PelletsBoiler:
return PelletsBoiler()._initialize(self.__modbus_connector)
def pelletsboiler(self, system:Systems, api_version:ApiVersions)->PelletsBoiler:
return PelletsBoiler(api_version=api_version)._initialize(self.__modbus_connector)

def solar(self, system:Systems)->Solar:
return Solar()._initialize(self.__modbus_connector)
Expand Down
2 changes: 1 addition & 1 deletion pysolarfocus/components/base/component.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

from pysolarfocus.components.base.performance_calculator import PerformanceCalculator

from ...modbus_wrapper import ModbusConnector
from .data_value import DataValue
from .enums import DataTypes, RegisterTypes
from .performance_calculator import PerformanceCalculator
from .register_slice import RegisterSlice


Expand Down
17 changes: 12 additions & 5 deletions pysolarfocus/components/pellets_boiler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from .base.component import Component
from .base.enums import DataTypes, RegisterTypes
from .base.data_value import DataValue
from .. import ApiVersions

class PelletsBoiler(Component):
def __init__(self,input_address=2400,holding_address=33400) -> None:
def __init__(self,input_address=2400,holding_address=-1,api_version:ApiVersions=ApiVersions.V_21_140) -> None:

if api_version.value >= ApiVersions.V_23_010.value:
holding_address=33400

super().__init__(input_address, holding_address)
self.temperature = DataValue(address=0,multiplier=0.1)
self.status = DataValue(address=1,type=DataTypes.UINT)
Expand All @@ -16,7 +21,9 @@ def __init__(self,input_address=2400,holding_address=33400) -> None:
self.octoplus_buffer_temperature_bottom = DataValue(address=10,multiplier=0.1)
self.octoplus_buffer_temperature_top = DataValue(address=11,multiplier=0.1)
self.log_wood = DataValue(address=12,type=DataTypes.UINT)
self.pellet_usage_last_fill = DataValue(address=14,count=2,multiplier=0.1)
self.pellet_usage_total = DataValue(address=16,count=2,multiplier=0.1)
self.heat_energy_total = DataValue(address=18,count=2,multiplier=0.1)
self.pellet_usage_reset = DataValue(address=12,register_type=RegisterTypes.Holding)

if api_version.value >= ApiVersions.V_23_010.value:
self.pellet_usage_last_fill = DataValue(address=14,count=2,multiplier=0.1)
self.pellet_usage_total = DataValue(address=16,count=2,multiplier=0.1)
self.heat_energy_total = DataValue(address=18,count=2,multiplier=0.1)
self.pellet_usage_reset = DataValue(address=12,register_type=RegisterTypes.Holding)

0 comments on commit d6bda6c

Please sign in to comment.