Skip to content

Commit

Permalink
feat: Manager ECS directly without climate
Browse files Browse the repository at this point in the history
  • Loading branch information
alepee committed Nov 29, 2024
1 parent 6286844 commit f643a0e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 152 deletions.
147 changes: 0 additions & 147 deletions custom_components/hitachi_yutaki/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ class HitachiYutakiClimateEntityDescription(ClimateEntityDescription):
),
)

DHW_CLIMATE_DESCRIPTIONS: Final[tuple[HitachiYutakiClimateEntityDescription, ...]] = (
HitachiYutakiClimateEntityDescription(
key="dhw_climate",
translation_key="dhw_climate",
),
)


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -95,18 +88,6 @@ async def async_setup_entry(
)
)

# Add DHW climate if configured
if coordinator.has_dhw():
entities.append(
HitachiYutakiDHWClimate(
coordinator=coordinator,
description=DHW_CLIMATE_DESCRIPTIONS[0],
device_info=DeviceInfo(
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_DHW}")},
),
)
)

async_add_entities(entities)


Expand Down Expand Up @@ -287,131 +268,3 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
f"{self._register_prefix}_eco_mode",
0 if preset_mode == PRESET_ECO else 1
)


class HitachiYutakiDHWClimate(CoordinatorEntity[HitachiYutakiDataCoordinator], ClimateEntity):
"""Representation of a Hitachi Yutaki DHW Climate."""

entity_description: HitachiYutakiClimateEntityDescription

def __init__(
self,
coordinator: HitachiYutakiDataCoordinator,
description: HitachiYutakiClimateEntityDescription,
device_info: DeviceInfo,
) -> None:
"""Initialize the climate entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_unique_id = f"{coordinator.slave}_dhw_climate"
self._attr_device_info = device_info
self._attr_has_entity_name = True

# Set supported features
self._attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)

# Set temperature settings
self._attr_min_temp = 30.0
self._attr_max_temp = 60.0
self._attr_target_temperature_step = 1.0
self._attr_temperature_unit = UnitOfTemperature.CELSIUS

# Set available modes
self._attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]

# Set available presets
self._attr_preset_modes = [
PRESET_DHW_OFF,
PRESET_DHW_STANDARD,
PRESET_DHW_HIGH_DEMAND,
]

@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
if self.coordinator.data is None:
return None

temp = self.coordinator.data.get("dhw_current_temp")
if temp is None:
return None

# Convert from 2's complement if necessary (16-bit signed integer)
if temp > 32767: # If highest bit is set (negative number)
temp = temp - 65536

return float(temp)

@property
def target_temperature(self) -> float | None:
"""Return the temperature we try to reach."""
if self.coordinator.data is None:
return None

temp = self.coordinator.data.get("dhw_target_temp")
if temp is None:
return None

return float(temp)

@property
def hvac_mode(self) -> HVACMode | None:
"""Return hvac operation mode."""
if self.coordinator.data is None:
return None

power = self.coordinator.data.get("dhw_power")
return HVACMode.HEAT if power == 1 else HVACMode.OFF

@property
def preset_mode(self) -> str | None:
"""Return the current preset mode."""
if self.coordinator.data is None:
return None

power = self.coordinator.data.get("dhw_power")
if power == 0:
return PRESET_DHW_OFF

high_demand = self.coordinator.data.get("dhw_mode")
return PRESET_DHW_HIGH_DEMAND if high_demand == 1 else PRESET_DHW_STANDARD

async def async_set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
return

await self.coordinator.async_write_register(
"dhw_target_temp",
int(temperature * 10)
)

async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
await self.coordinator.async_write_register(
"dhw_power",
1 if hvac_mode == HVACMode.HEAT else 0
)

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode not in self.preset_modes:
return

if preset_mode == PRESET_DHW_OFF:
await self.coordinator.async_write_register("dhw_power", 0)
return

# For all other modes, ensure power is on
await self.coordinator.async_write_register("dhw_power", 1)

# Set high demand mode
await self.coordinator.async_write_register(
"dhw_mode",
1 if preset_mode == PRESET_DHW_HIGH_DEMAND else 0
)
2 changes: 1 addition & 1 deletion custom_components/hitachi_yutaki/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/alepee/hass-hitachi_yutaki/issues",
"requirements": [
"pymodbus>=3.0.0"
"pymodbus==3.6.9"
],
"version": "1.0.0"
}
4 changes: 2 additions & 2 deletions custom_components/hitachi_yutaki/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class HitachiYutakiNumberEntityDescription(NumberEntityDescription):
key="dhw_target_temp",
translation_key="dhw_target_temperature",
description="Target temperature for domestic hot water",
native_min_value=0,
native_max_value=80,
native_min_value=30,
native_max_value=60,
native_step=1,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
register_key="dhw_target_temp",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hitachi_yutaki/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ class HitachiYutakiSwitchEntityDescription(SwitchEntityDescription):
translation_key="boost",
description="Temporarily boost DHW production",
register_key="dhw_boost",
entity_registry_enabled_default=False,
),
HitachiYutakiSwitchEntityDescription(
key="high_demand",
translation_key="high_demand",
icon="mdi:crowd",
description="Enable high demand mode for increased DHW production",
register_key="dhw_mode",
entity_category=EntityCategory.CONFIG,
),
HitachiYutakiSwitchEntityDescription(
key="antilegionella",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hitachi_yutaki/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
"name": "Boost"
},
"high_demand": {
"name": "Haute Demande"
"name": "Demande intense"
},
"antilegionella": {
"name": "Anti-légionelle"
Expand Down

0 comments on commit f643a0e

Please sign in to comment.