Skip to content

Commit

Permalink
* Fix entity migration
Browse files Browse the repository at this point in the history
* Add switch silent mode
* Re-Add service write
  • Loading branch information
BenPru committed Oct 31, 2023
1 parent e0db55b commit 80fb007
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
22 changes: 22 additions & 0 deletions custom_components/luxtronik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
)

from .const import (
ATTR_PARAMETER,
ATTR_VALUE,
CONF_COORDINATOR,
CONF_HA_SENSOR_PREFIX,
CONF_MAX_DATA_LENGTH,
Expand All @@ -19,6 +21,8 @@
DOMAIN,
LOGGER,
PLATFORMS,
SERVICE_WRITE,
SERVICE_WRITE_SCHEMA,
SensorKey as SK,
)
from .coordinator import LuxtronikCoordinator
Expand Down Expand Up @@ -48,9 +52,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

# hass.config_entries.async_setup_platforms(entry, PLATFORMS)

await hass.async_add_executor_job(setup_hass_services, hass, entry)

return True


def setup_hass_services(hass: HomeAssistant, entry: ConfigEntry):
"""Home Assistant services."""

def write_parameter(service):
"""Write a parameter to the Luxtronik heatpump."""
parameter = service.data.get(ATTR_PARAMETER)
value = service.data.get(ATTR_VALUE)
coordinator = LuxtronikCoordinator.connect(hass, entry)
coordinator.write(parameter, value)

hass.services.register(
DOMAIN, SERVICE_WRITE, write_parameter, schema=SERVICE_WRITE_SCHEMA
)


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
Expand Down Expand Up @@ -107,6 +128,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
ent_reg = None

def _up(ident: str, new_id: SK, platform: P = P.SENSOR) -> None:
nonlocal prefix, ent_reg
if prefix is None or ent_reg is None:
prefix = config_entry.data[CONF_HA_SENSOR_PREFIX]
ent_reg = async_get(hass)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/luxtronik/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
HVAC_PRESET_MAPPING: dict[str, str] = {
LuxMode.off.value: PRESET_NONE,
LuxMode.automatic.value: PRESET_NONE,
LuxMode.party.value: PRESET_BOOST,
LuxMode.party.value: PRESET_COMFORT,
LuxMode.second_heatsource.value: PRESET_BOOST,
LuxMode.holidays.value: PRESET_AWAY,
}

Expand Down
20 changes: 17 additions & 3 deletions custom_components/luxtronik/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
DEFAULT_PORT: Final = 8889
DEFAULT_TIMEOUT: Final = 60.0
DEFAULT_MAX_DATA_LENGTH: Final = 10000


SERVICE_WRITE: Final = "write"
ATTR_PARAMETER: Final = "parameter"
ATTR_VALUE: Final = "value"

SERVICE_WRITE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_PARAMETER): cv.string,
vol.Required(ATTR_VALUE): vol.Any(cv.Number, cv.string),
}
)
# endregion Conf

# region Lux Definitions
Expand Down Expand Up @@ -330,9 +342,6 @@ class LuxParameter(StrEnum):
# "879 ID_Waermemenge_SW ": "0",
# "880 ID_Waermemenge_Datum ": "1483648906", <-- Unix timestamp! 5.1.2017

# "1060 ID_Waermemenge_Reset ": "535051",
# "1061 ID_Waermemenge_Reset_2 ": "0",

P0882_SOLAR_OPERATION_HOURS: Final = "parameters.ID_BSTD_Solar"
P0883_SOLAR_PUMP_MAX_TEMPERATURE_COLLECTOR: Final = (
"parameters.ID_Einst_TDC_Koll_Max_akt"
Expand All @@ -355,6 +364,9 @@ class LuxParameter(StrEnum):
P1059_ADDITIONAL_HEAT_GENERATOR_AMOUNT_COUNTER: Final = (
"parameters.ID_Waermemenge_ZWE"
)
# "1060 ID_Waermemenge_Reset ": "535051",
# "1061 ID_Waermemenge_Reset_2 ": "0",
P1087_SILENT_MODE: Final = "parameters.Unknown_Parameter_1087" # Silent mode On/Off
P1119_LAST_DEFROST_TIMESTAMP: Final = (
"parameters.Unknown_Parameter_1119" # 1685073431 -> 26.5.23 05:57
)
Expand Down Expand Up @@ -545,6 +557,7 @@ class LuxVisibility(StrEnum):
V0324_ADDITIONAL_HEAT_GENERATOR_AMOUNT_COUNTER: Final = (
"visibilities.ID_Visi_Waermemenge_ZWE"
)
V0357_SILENT_MODE_TIME_MENU: Final = "visibilities.Unknown_Parameter_357"


# endregion visibilities
Expand Down Expand Up @@ -681,6 +694,7 @@ class SensorKey(StrEnum):
COOLING_TARGET_TEMPERATURE_MK2 = "cooling_target_temperature_mk2"
COOLING_TARGET_TEMPERATURE_MK3 = "cooling_target_temperature_mk3"
SWITCHOFF_REASON = "switchoff_reason"
SILENT_MODE = "silent_mode"


# endregion Keys
Expand Down
2 changes: 1 addition & 1 deletion custom_components/luxtronik/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"after_dependencies": [],
"codeowners": ["@BenPru"],
"iot_class": "local_polling",
"version": "2023.10.30",
"version": "2023.10.31",
"homeassistant": "2023.1.0",
"dhcp": [
{ "macaddress": "000E8C*" },
Expand Down
9 changes: 9 additions & 0 deletions custom_components/luxtronik/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
write:
description: Write a parameter on the luxtronik heatpump.
fields:
parameter:
description: ID of the value to write.
example: "ID_Ba_Bw_akt"
value:
description: Value to write.
example: "Automatic"
7 changes: 7 additions & 0 deletions custom_components/luxtronik/switch_entities_predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
entity_registry_enabled_default=False,
# device_class=SensorDeviceClass.HEAT
),
LuxtronikSwitchDescription(
luxtronik_key=LP.P1087_SILENT_MODE,
key=SensorKey.SILENT_MODE,
icon="mdi:volume-minus",
entity_category=EntityCategory.CONFIG,
visibility=LV.V0357_SILENT_MODE_TIME_MENU,
),
# LuxtronikSwitchDescription(
# luxtronik_key=LP.P0870_AMOUNT_COUNTER_ACTIVE,
# key="amount_counter_active",
Expand Down
3 changes: 3 additions & 0 deletions custom_components/luxtronik/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
},
"cooling": {
"name": "Cooling"
},
"silent_mode": {
"name": "Silent mode"
}
},
"update": {
Expand Down

0 comments on commit 80fb007

Please sign in to comment.