Skip to content

Commit 85096b0

Browse files
committed
Merge branch 'main' of github.com:OStrama/weishaupt_modbus
2 parents 7af9874 + b7c2111 commit 85096b0

File tree

6 files changed

+67
-25
lines changed

6 files changed

+67
-25
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ MadOne and OStrama are working together on this version.
77
## For users of MadOne's original weishaupt_modbus integration:
88
* When doing nothing than simply installing the integration, the long term statistics will be split into new entities,
99
since the sensor domain is different.
10-
* To avoid this, edit the file "const.py" in the integration's directory as follows:
11-
replace the string
12-
PREFIX = "weishaupt_wbb"
13-
by
14-
PREFIX = "weishaupt_modbus"
10+
* To avoid this, change the default prefix entry in the configuration dialog from
11+
weishaupt_wbb
12+
to
13+
weishaupt_modbus
1514
please do not change the intents or any other parts of the file to avoid issues
1615

1716
## For users of OStrama's weishaupt_wbb integration:
@@ -61,12 +60,18 @@ custom_components
6160
```
6261
## Configuration
6362

64-
![Bildschirmfoto vom 2024-07-31 21-46-18](https://github.com/user-attachments/assets/45ad403e-c721-40bd-b723-95fe05fca5c5)
63+
![image](https://github.com/user-attachments/assets/8549938f-a059-4a92-988c-ba329f3cd758)
6564

66-
Just enter the IP of your Weishaupt heatpump. Port should be ok at default unless you changed it in the Heatpump configuration.
65+
The only mandatory parameter is the IP-Address of your heatpump. The port should be ok at default unless you changed it in the Heatpump configuration.
66+
67+
The "prefix" should only be changed when migrating from MadOnes original integration to this one to avoid splitting of sensor history
68+
69+
The "Device Postfix" has a default value of "". It can be used to add multiple heat pumps to one home assistant. For compatibility this should be left empty. If you want to add another heat pump, use a name that help to identify the devices.
70+
71+
The "Kennfeld-File" can be choosen to read in the right power mapping according to your type of heat pump:
6772

6873
The heat power "Wärmeleistung" is calculated from the "Leistungsanforderung" in dependency of outside temperature and water temperature.
69-
This is type specific. The data stored in the integration fit to a WBB 12. If you have another heat pump please update the "weishaupt_wbb_kennfeld.json" file according to the graphs foudn in the documentation of your heat pump. In the given file the data have been read out from the graphs found in the documentation in a manual way.
74+
This is type specific. The data stored in the integration fit to a WBB 12. If the file you've parameterized does not exist, the integration will create a file that fits for a WBB12. If you have another heat pump please update the Kennfeld-File file according to the graphs found in the documentation of your heat pump and restart Home Assistant. In the given file the data have been read out from the graphs found in the documentation in a manual way.
7075

7176

7277
You have to enable modbus in your heatpump settings.

custom_components/weishaupt_modbus/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""init."""
22

3+
import warnings
4+
35
from homeassistant.config_entries import ConfigEntry
46
from homeassistant.core import HomeAssistant
57

@@ -39,6 +41,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3941
entry.runtime_data.close()
4042
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
4143
if unload_ok:
42-
hass.data[CONST.DOMAIN].pop(entry.entry_id)
44+
try:
45+
hass.data[CONST.DOMAIN].pop(entry.entry_id)
46+
except KeyError:
47+
warnings.warn("KeyError: " + CONST.DOMAIN)
4348

4449
return unload_ok

custom_components/weishaupt_modbus/config_flow.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55
import voluptuous as vol
66

77
from homeassistant import config_entries, exceptions
8-
from homeassistant.const import CONF_HOST, CONF_PORT
8+
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_PREFIX
99
from homeassistant.core import HomeAssistant
1010
import homeassistant.helpers.config_validation as cv
1111

1212
# from . import wp
13-
from .const import CONST
13+
from .const import CONST, CONF_DEVICE_POSTFIX, CONF_KENNFELD_FILE
1414

1515
# DATA_SCHEMA = vol.Schema({("host"): str, ("port"): cv.port})
1616
DATA_SCHEMA = vol.Schema(
17-
{vol.Required(CONF_HOST): str, vol.Optional(CONF_PORT, default="502"): cv.port}
17+
{
18+
vol.Required(CONF_HOST): str,
19+
vol.Optional(CONF_PORT, default="502"): cv.port,
20+
vol.Optional(CONF_PREFIX, default=CONST.DEF_PREFIX): str,
21+
vol.Optional(CONF_DEVICE_POSTFIX, default=""): str,
22+
vol.Optional(CONF_KENNFELD_FILE, default=CONST.DEF_KENNFELDFILE): str,
23+
}
1824
)
1925

2026

custom_components/weishaupt_modbus/const.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
UnitOfVolumeFlowRate,
1313
)
1414

15+
CONF_DEVICE_POSTFIX = "Device-Postfix"
16+
CONF_KENNFELD_FILE = "Kennfeld-File"
17+
1518

1619
@dataclass(frozen=True)
1720
class MainConstants:
1821
"""Main constants."""
1922

2023
DOMAIN = "weishaupt_modbus"
21-
SCAN_INTERVAL = timedelta(minutes=1)
24+
SCAN_INTERVAL = timedelta(seconds=30)
2225
UNIQUE_ID = "unique_id"
2326
APPID = 100
24-
KENNFELDFILE = "weishaupt_wbb_kennfeld.json"
25-
PREFIX = "weishaupt_wbb"
27+
DEF_KENNFELDFILE = "weishaupt_wbb_kennfeld.json"
28+
DEF_PREFIX = "weishaupt_wbb"
2629

2730

2831
CONST = MainConstants()

custom_components/weishaupt_modbus/entities.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SensorEntity,
1515
SensorStateClass,
1616
)
17-
from homeassistant.const import CONF_PORT
17+
from homeassistant.const import CONF_PORT, CONF_PREFIX, CONF_DOMAIN
1818
from homeassistant.core import callback
1919
from homeassistant.helpers.device_registry import DeviceInfo
2020

@@ -24,7 +24,7 @@
2424
DataUpdateCoordinator,
2525
)
2626

27-
from .const import CONST, FORMATS, TYPES # , DOMAIN
27+
from .const import CONST, FORMATS, TYPES, CONF_DEVICE_POSTFIX # , DOMAIN
2828
from .hpconst import DEVICES, TEMPRANGE_STD
2929
from .items import ModbusItem
3030
from .kennfeld import PowerMap
@@ -101,7 +101,7 @@ def __init__(self, hass, my_api, modbusitems):
101101
# Name of the data. For logging purposes.
102102
name="weishaupt-coordinator",
103103
# Polling interval. Will only be polled if there are subscribers.
104-
update_interval=timedelta(seconds=30),
104+
update_interval=CONST.SCAN_INTERVAL,
105105
# Set always_update to `False` if the data returned from the
106106
# api can be compared via `__eq__` to avoid duplicate updates
107107
# being dispatched to listeners
@@ -239,8 +239,23 @@ def __init__(self, config_entry, modbus_item, modbus_api) -> None:
239239
self._config_entry = config_entry
240240
self._modbus_item = modbus_item
241241
self._attr_name = self._modbus_item.name
242-
self._attr_unique_id = CONST.PREFIX + self._modbus_item.name
243-
self._dev_device = self._modbus_item.device
242+
243+
dev_postfix = ""
244+
try:
245+
dev_postfix = "_" + self._config_entry.data[CONF_DEVICE_POSTFIX]
246+
except KeyError:
247+
warnings.warn("Device postfix not defined, use default: ")
248+
249+
dev_prefix = CONST.DEF_PREFIX
250+
try:
251+
dev_prefix = "_" + self._config_entry.data[CONF_PREFIX]
252+
except KeyError:
253+
warnings.warn("Device prefix not defined, use default: " + CONST.DEF_PREFIX)
254+
255+
self._attr_unique_id = (
256+
dev_prefix + self._modbus_item.name + dev_postfix
257+
) # CONST.PREFIX + self._modbus_item.name
258+
self._dev_device = self._modbus_item.device + dev_postfix
244259
self._modbus_api = modbus_api
245260

246261
if self._modbus_item._format != FORMATS.STATUS:
@@ -388,10 +403,11 @@ class MyCalcSensorEntity(MySensorEntity):
388403
"""
389404

390405
# calculates output from map
391-
my_map = PowerMap()
406+
my_map = None
392407

393408
def __init__(self, config_entry, modbus_item, coordinator, idx) -> None:
394409
MySensorEntity.__init__(self, config_entry, modbus_item, coordinator, idx)
410+
self.my_map = PowerMap(self._config_entry)
395411

396412
@callback
397413
def _handle_coordinator_update(self) -> None:

custom_components/weishaupt_modbus/kennfeld.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from numpy.polynomial import Chebyshev
77
# from scipy.interpolate import CubicSpline
88

9-
from .const import CONST
9+
from .const import CONF_KENNFELD_FILE
1010

1111

1212
class PowerMap:
@@ -71,19 +71,26 @@ class PowerMap:
7171

7272
interp_y = []
7373

74-
def __init__(self) -> None:
74+
_config_entry = None
75+
76+
def __init__(self, config_entry) -> None:
7577
"""Initialise the PowerMap class."""
7678
# try to load values from json file
79+
self._config_entry = config_entry
7780

7881
try:
79-
openfile = open(CONST.KENNFELDFILE, "r", encoding="utf-8")
82+
openfile = open(
83+
self._config_entry.data[CONF_KENNFELD_FILE], "r", encoding="utf-8"
84+
)
8085
except IOError:
8186
kennfeld = {
8287
"known_x": self.known_x,
8388
"known_y": self.known_y,
8489
"known_t": self.known_t,
8590
}
86-
with open(CONST.KENNFELDFILE, "w", encoding="utf-8") as outfile:
91+
with open(
92+
self._config_entry.data[CONF_KENNFELD_FILE], "w", encoding="utf-8"
93+
) as outfile:
8794
json.dump(kennfeld, outfile)
8895
else:
8996
json_object = json.load(openfile)

0 commit comments

Comments
 (0)