Skip to content

Commit

Permalink
Improve version handling (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
LavermanJJ committed Mar 29, 2023
1 parent b98d130 commit 0c1bfbd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
11 changes: 7 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from pysolarfocus import SolarfocusAPI,Systems,ApiVersions

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

solarfocus.connect()
# Fetch the values
solarfocus.update()

# Print the values
print("Solarfocus "+ solarfocus.system.name +", version " + str(solarfocus.api_version.value))
print(solarfocus)
print(solarfocus.heating_circuits[0])
print("\n")
print(solarfocus.boilers[0])
Expand All @@ -23,4 +25,5 @@
print("\n")
print(solarfocus.photovoltaic)
print("\n")
print(solarfocus.solar)
print(solarfocus.solar)
print("\n")
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.6.0"
version = "3.6.1"
description = "Unofficial, local Solarfocus client"
authors = ["Jeroen Laverman <jjlaverman@web.de>"]
license = "Apache-2.0"
Expand Down
43 changes: 32 additions & 11 deletions pysolarfocus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Python client lib for Solarfocus"""
__version__ = "3.6.0"
__version__ = "3.6.1"

from enum import Enum
from packaging import version
Expand All @@ -15,11 +15,18 @@ class Systems(str, Enum):
Vampair = "Vampair"
Therminator = "Therminator"

class ApiVersions(Enum):
V_21_140 = version.parse("21.140")
V_22_090 = version.parse("22.090")
V_23_010 = version.parse("23.010")
V_23_020 = version.parse("23.020")
class ApiVersions(str, Enum):
"""
Supported Solarfocus API versions by this library
"""
V_21_140 = "21.140"
V_22_090 = "22.090"
V_23_010 = "23.010"
V_23_020 = "23.020"

def greater_or_equal(self, api_version)->bool:
return version.parse(self.value) >= version.parse(api_version)


from .modbus_wrapper import ModbusConnector
from .component_factory import ComponentFactory
Expand All @@ -41,7 +48,7 @@ def __init__(self,
heating_circuit_count:int = 1,
buffer_count:int = 1,
boiler_count:int = 1,
fresh_water_module_count:int =1,
fresh_water_module_count:int = 1,
system:Systems=Systems.Vampair,
port:int=PORT,
slave_id:int=SLAVE_ID,
Expand All @@ -62,7 +69,7 @@ def __init__(self,
self.heating_circuits = self.__factory.heating_circuit(system,heating_circuit_count)
self.boilers = self.__factory.boiler(system,boiler_count)
self.buffers = self.__factory.buffer(system,buffer_count,api_version)
if self._api_version.value >= ApiVersions.V_23_020.value:
if self._api_version.greater_or_equal(ApiVersions.V_23_020.value):
self.fresh_water_modules = self.__factory.fresh_water_modules(system,fresh_water_module_count)

#Single components
Expand Down Expand Up @@ -120,24 +127,38 @@ def update_boiler(self) -> bool:

def update_fresh_water_modules(self) -> bool:
"""Read values from Heating System"""
if self.api_version.value >= ApiVersions.V_23_020.value:
if self._api_version.greater_or_equal(ApiVersions.V_23_020.value):
for fresh_water_module in self.fresh_water_modules:
if not fresh_water_module.update():
return False
return True

def update_heatpump(self) -> bool:
"""Read values from Heating System"""
return self.heatpump.update()
if self._system is Systems.Vampair:
return self.heatpump.update()
return True

def update_photovoltaic(self) -> bool:
"""Read values from Heating System"""
return self.photovoltaic.update()

def update_pelletsboiler(self) -> bool:
"""Read values from Pellets boiler"""
return self.pelletsboiler.update()
if self._system is Systems.Therminator:
return self.pelletsboiler.update()
return True

def update_solar(self) -> bool:
"""Read values from Solar"""
return self.solar.update()


def __repr__(self) -> str:
s = ["-"*50]
s.append(f"{self.__class__.__name__}, v{__version__}")
s.append("-"*50)
s.append(f"+ System: {self.system.name}")
s.append(f"+ Version: {self._api_version}")
s.append("-"*50)
return "\n".join(s)
2 changes: 1 addition & 1 deletion pysolarfocus/component_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def boiler(self, system:Systems,count:int)->list[Boiler]:
def buffer(self, system:Systems,count:int, api_version:ApiVersions)->list[Buffer]:
input_addresses = list(range(1900,1900+(20*count),20))
holding_addresses = -1
if api_version.value >= ApiVersions.V_22_090.value:
if api_version.greater_or_equal(ApiVersions.V_22_090.value):
holding_addresses = list(range(34000,34000+(50*count),50))
buffers = []
for i in range(count):
Expand Down
2 changes: 1 addition & 1 deletion pysolarfocus/components/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self,input_address:int=1900, holding_address=-1, api_version:ApiVer
self.state = DataValue(address=3,type=DataTypes.UINT)
self.mode = DataValue(address=4,type=DataTypes.UINT)

if api_version.value >= ApiVersions.V_22_090.value:
if api_version.greater_or_equal(ApiVersions.V_22_090.value):
self.external_top_temperature_x44 = DataValue(address=0,multiplier=10,register_type=RegisterTypes.Holding)
self.external_middle_temperature_x36 = DataValue(address=1,multiplier=10,register_type=RegisterTypes.Holding)
self.external_bottom_temperature_x35 = DataValue(address=2,multiplier=10,register_type=RegisterTypes.Holding)
Expand Down
6 changes: 3 additions & 3 deletions pysolarfocus/components/pellets_boiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class PelletsBoiler(Component):
def __init__(self,input_address=2400,holding_address=-1,api_version:ApiVersions=ApiVersions.V_21_140) -> None:

if api_version.value >= ApiVersions.V_22_090.value:
if api_version.greater_or_equal(ApiVersions.V_22_090.value):
holding_address=33400

super().__init__(input_address, holding_address)
Expand All @@ -22,11 +22,11 @@ def __init__(self,input_address=2400,holding_address=-1,api_version:ApiVersions=
self.octoplus_buffer_temperature_top = DataValue(address=11,multiplier=0.1)
self.log_wood = DataValue(address=12,type=DataTypes.UINT)

if api_version.value >= ApiVersions.V_22_090.value:
if api_version.greater_or_equal(ApiVersions.V_22_090.value):
self.sweep_function_start_stop = DataValue(address=10,register_type=RegisterTypes.Holding)
self.sweep_function_extend = DataValue(address=11,register_type=RegisterTypes.Holding)

if api_version.value >= ApiVersions.V_23_010.value:
if api_version.greater_or_equal(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)
Expand Down

0 comments on commit 0c1bfbd

Please sign in to comment.