Skip to content

Commit

Permalink
Add party / pause
Browse files Browse the repository at this point in the history
  • Loading branch information
MadOne committed Aug 8, 2024
1 parent 8e18c32 commit c1c4941
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 29 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
120 changes: 112 additions & 8 deletions custom_components/weishaupt_modbus/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from homeassistant.components.number import NumberEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT, UnitOfTemperature
from homeassistant.const import CONF_HOST, CONF_PORT, UnitOfTemperature, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -33,7 +33,13 @@ async def async_setup_entry(
# host = "10.10.1.225"
# port = "502"
async_add_entities(
[WW_Normal(host, port), WW_Absenk(host, port)], update_before_add=True
[
WW_Normal(host, port),
WW_Absenk(host, port),
HK_Party(host, port),
HK_Pause(host, port),
],
update_before_add=True,
)


Expand All @@ -52,9 +58,9 @@ def __init__(self, host, port) -> None:
"""Init."""
self._host = host
self._port = port
whp = wp.heat_pump(host, port)
whp.connect()
self._attr_native_value = whp.WW_Normal
# whp = wp.heat_pump(host, port)
# whp.connect()
# self._attr_native_value = whp.WW_Normal
# self.async_write_ha_state()

async def async_set_native_value(self, value: float) -> None:
Expand Down Expand Up @@ -95,9 +101,9 @@ def __init__(self, host, port) -> None:
"""Init."""
self._host = host
self._port = port
whp = wp.heat_pump(host, port)
whp.connect()
self._attr_native_value = whp.WW_Absenk
# whp = wp.heat_pump(host, port)
# whp.connect()
# self._attr_native_value = whp.WW_Absenk
# self.async_write_ha_state()

async def async_set_native_value(self, value: float) -> None:
Expand All @@ -121,3 +127,101 @@ def device_info(self) -> DeviceInfo:
return {
"identifiers": {(DOMAIN, "Warmwasser")},
}


class HK_Party(NumberEntity):
"""Representation of a WEM Portal number."""

_attr_name = "HK Party"
_attr_unique_id = DOMAIN + _attr_name
_attr_native_value = 0
_attr_should_poll = True
_attr_native_min_value = 0
_attr_native_max_value = 12
_attr_native_step = 0.5
_attr_native_unit_of_measurement = UnitOfTime.HOURS

def __init__(self, host, port) -> None:
"""Init."""
self._host = host
self._port = port
# whp = wp.heat_pump(host, port)
# whp.connect()
# party_pause = whp.HK_Pause_Party
# if party_pause > 25:
# self._attr_native_value = (party_pause - 25) * 0.5
# else:
# self._attr_native_value = 0

async def async_set_native_value(self, value: float) -> None:
"""Update the current value."""
whp = wp.heat_pump(self._host, self._port)
whp.connect()
whp.HK_Pause_Party = int(25 + (value / 0.5))
self.async_write_ha_state()

async def async_update(self) -> None:
"""Update Entity Only used by the generic entity update service."""
whp = wp.heat_pump(self._host, self._port)
whp.connect()
party_pause = whp.HK_Pause_Party
if party_pause > 25:
self._attr_native_value = (party_pause - 25) * 0.5
else:
self._attr_native_value = 0

@property
def device_info(self) -> DeviceInfo:
"""Information about this entity/device."""
return {
"identifiers": {(DOMAIN, "Heizkreis")},
}


class HK_Pause(NumberEntity):
"""Representation of a WEM Portal number."""

_attr_name = "HK Pause"
_attr_unique_id = DOMAIN + _attr_name
_attr_native_value = 0
_attr_should_poll = True
_attr_native_min_value = 0
_attr_native_max_value = 12
_attr_native_step = 0.5
_attr_native_unit_of_measurement = UnitOfTime.HOURS

def __init__(self, host, port) -> None:
"""Init."""
self._host = host
self._port = port
# whp = wp.heat_pump(host, port)
# whp.connect()
# party_pause = whp.HK_Pause_Party
# if party_pause < 25:
# self._attr_native_value = (25 - party_pause) * 0.5
# else:
# self._attr_native_value = 0

async def async_set_native_value(self, value: float) -> None:
"""Update the current value."""
whp = wp.heat_pump(self._host, self._port)
whp.connect()
whp.HK_Pause_Party = int(25 - (value / 0.5))
self.async_write_ha_state()

async def async_update(self) -> None:
"""Update Entity Only used by the generic entity update service."""
whp = wp.heat_pump(self._host, self._port)
whp.connect()
party_pause = whp.HK_Pause_Party
if party_pause < 25:
self._attr_native_value = (25 - party_pause) * 0.5
else:
self._attr_native_value = 0

@property
def device_info(self) -> DeviceInfo:
"""Information about this entity/device."""
return {
"identifiers": {(DOMAIN, "Heizkreis")},
}
44 changes: 23 additions & 21 deletions custom_components/weishaupt_modbus/wp.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,30 +299,32 @@ def HK_Betriebsart(self):
@property
def HK_Pause_Party(self):
"""Energy used today."""
val = self.WWP.read_holding_registers(41104, slave=1).registers[0]
if val == 25:
return "Automatik"
if val < 25:
time = (25 - val) * 0.5
return "Pausenzeit " + time + "h"
if val > 25:
time = (val - 25) * 0.5
return "Partyzeit " + val * 0.5 + "h"
return self.WWP.read_holding_registers(41104, slave=1).registers[0]
# val = self.WWP.read_holding_registers(41104, slave=1).registers[0]
# if val == 25:
# return "Automatik"
# if val < 25:
# time = (25 - val) * 0.5
# return "Pausenzeit " + time + "h"
# if val > 25:
# time = (val - 25) * 0.5
# return "Partyzeit " + val * 0.5 + "h"

@HK_Pause_Party.setter
def HK_Pause_Party(self, val):
party_pause = val.split(" ")[0]
time = val.split(" ")[1]
time_value = time[:-1]
if party_pause == "Automatik":
return_value = 25
if party_pause == "Pausenzeit":
return_value = 25 - (time_value * 0.5)

if val == "Partyzeit":
return_value = 25 + (time_value * 0.5)

self.WWP.write_register(41104, return_value, slave=1)
# party_pause = val.split(" ")[0]
# time = val.split(" ")[1]
# time_value = time[:-1]
# if party_pause == "Automatik":
# return_value = 25
# if party_pause == "Pausenzeit":
# return_value = 25 - (time_value * 0.5)

# if val == "Partyzeit":
# return_value = 25 + (time_value * 0.5)

# self.WWP.write_register(41104, return_value, slave=1)
self.WWP.write_register(41104, val, slave=1)

#####################
# Warm Water #
Expand Down

0 comments on commit c1c4941

Please sign in to comment.