Skip to content

Added several new device information #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions custom_components/melcloud_custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ def __init__(self, device: Device) -> None:
self.name = device.name
self._extra_attributes = None
self._dev_conf = None
self._energy_report = None
self._coordinator: DataUpdateCoordinator | None = None

async def _async_update(self):
"""Pull the latest data from MELCloud."""
self._dev_conf = None
self._energy_report = None
await self.device.update()

async def async_create_coordinator(
Expand Down Expand Up @@ -300,6 +302,17 @@ def building_id(self):
"""Return building ID of the device."""
return self.device.building_id

@property
def energy_report(self):
"""Return energy_report of the device."""
if self._energy_report is None:
energy_report = self.device._energy_report
if energy_report is None:
self._energy_report = {}
else:
self._energy_report = energy_report
return self._energy_report

@property
def device_conf(self):
"""Return device_conf of the device."""
Expand All @@ -311,6 +324,26 @@ def device_conf(self):
self._dev_conf = dev_conf.get("Device", {})
return self._dev_conf

@property
def daily_heating_energy_consumed(self) -> Optional[int]:
"""Return wifi signal."""
return self.device_conf.get("DailyHeatingEnergyConsumed")

@property
def daily_heating_energy_produced(self) -> Optional[int]:
"""Return wifi signal."""
return self.device_conf.get("DailyHeatingEnergyProduced")

@property
def daily_cooling_energy_consumed(self) -> Optional[int]:
"""Return wifi signal."""
return self.device_conf.get("DailyCoolingEnergyConsumed")

@property
def daily_cooling_energy_produced(self) -> Optional[int]:
"""Return wifi signal."""
return self.device_conf.get("DailyCoolingEnergyProduced")

@property
def wifi_signal(self) -> Optional[int]:
"""Return wifi signal."""
Expand Down
17 changes: 17 additions & 0 deletions custom_components/melcloud_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ClimateEntityFeature,
HVACAction,
HVACMode,
HVACAction,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
Expand Down Expand Up @@ -74,6 +75,11 @@
}
ATA_HVAC_HVANE_REVERSE_LOOKUP = {v: k for k, v in ATA_HVAC_HVANE_LOOKUP.items()}

ATW_ZONE_HVAC_STATE_LOOKUP: dict[str, HVACMode] = {
atw.ZONE_STATUS_HEAT: HVACAction.HEATING,
atw.ZONE_STATUS_COOL: HVACAction.COOLING,
atw.ZONE_STATUS_IDLE: HVACAction.IDLE,
}

ATW_ZONE_HVAC_MODE_LOOKUP = {
atw.ZONE_OPERATION_MODE_HEAT: HVACMode.HEAT,
Expand Down Expand Up @@ -389,6 +395,17 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
props["power"] = True
await self.api.async_set(props)

@property
def hvac_action(self) -> HVACAction:
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
state = self._zone.status
mode = self._zone.operation_mode
if not self._device.power or mode is None:
return HVACAction.OFF
return ATW_ZONE_HVAC_STATE_LOOKUP.get(state, HVACAction.OFF)

@property
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac operation modes."""
Expand Down
53 changes: 52 additions & 1 deletion custom_components/melcloud_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,57 @@ class MelcloudSensorEntityDescription(
),
)
ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
MelcloudSensorEntityDescription(
key="daily_heating_energy_consumed",
name="Daily Heating Energy Consumed",
icon="mdi:heat-pump",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
value_fn=lambda x: x.daily_heating_energy_consumed,
enabled=lambda x: True,
entity_registry_enabled_default=False,
),
MelcloudSensorEntityDescription(
key="daily_cooling_energy_consumed",
name="Daily Cooling Energy Consumed",
icon="mdi:sun-snowflake",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
value_fn=lambda x: x.daily_cooling_energy_consumed,
enabled=lambda x: True,
entity_registry_enabled_default=False,
),
MelcloudSensorEntityDescription(
key="daily_heating_energy_produced",
name="Daily Heating Energy Produced",
icon="mdi:factory",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
value_fn=lambda x: x.daily_heating_energy_produced,
enabled=lambda x: True,
entity_registry_enabled_default=False,
),
MelcloudSensorEntityDescription(
key="daily_cooling_energy_produced",
name="Daily Cooling Energy Produced",
icon="mdi:factory",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
value_fn=lambda x: x.daily_cooling_energy_produced,
enabled=lambda x: True,
entity_registry_enabled_default=False,
),
MelcloudSensorEntityDescription(
key="wifi_signal",
name="WiFi Signal",
icon="mdi:signal",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
value_fn=lambda x: x.wifi_signal,
enabled=lambda x: True,
entity_registry_enabled_default=False,
),
MelcloudSensorEntityDescription(
key="outside_temperature",
name="Outside Temperature",
Expand All @@ -99,7 +150,7 @@ class MelcloudSensorEntityDescription(
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda x: x.device.tank_temperature,
enabled=lambda x: True,
enabled=lambda x: x.device_info.get("HasHotWaterTank", False),
),
)
ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
Expand Down
1 change: 1 addition & 0 deletions custom_components/melcloud_custom/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def async_setup_entry(
[
AtwWaterHeater(mel_device, mel_device.device)
for mel_device in mel_devices[DEVICE_TYPE_ATW]
if mel_device.device_info.get("HasHotWaterTank", False)
],
True,
)
Expand Down