Skip to content

Commit

Permalink
Added Current Power Sensor for systems that support it, enabled RTS &…
Browse files Browse the repository at this point in the history
… MPC API calls on VRC700 systems
  • Loading branch information
signalkraft committed Mar 1, 2024
1 parent a460de4 commit f563792
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 23 deletions.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Feature request
about: Request a new feature
title: ''
labels: ''
assignees: ''

---

### Before requesting a new feature / a new sensor

- [ ] The feature I'm requesting exists in the myVAILLANT app, and I attached a screenshot
- [ ] I [tested the latest release](https://my.home-assistant.io/redirect/hacs_repository/?owner=signalkraft&repository=mypyllant-component), and it's missing there
- [ ] I've [attached exported data](https://signalkraft.com/mypyllant-component/3-contributing/#contributing-test-data) of my system

### Describe the feature you want

Please describe what you were trying to do, what happened, and what you expected to happen.

### Screenshot

Attach a screenshot of the functionality in the myVAILLANT app.

### Export data

```
Attach exported test data here
```
2 changes: 1 addition & 1 deletion custom_components/mypyllant/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def _async_update_data(self) -> list[System]:
data = [
s
async for s in await self.hass.async_add_executor_job(
self.api.get_systems, True, True, True
self.api.get_systems, True, True, True, True
)
]
return data
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mypyllant/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/signalkraft/mypyllant-component/issues",
"requirements": [
"myPyllant==0.7.25"
"myPyllant==0.7.26"
],
"version": "v0.7.3"
}
34 changes: 31 additions & 3 deletions custom_components/mypyllant/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
UnitOfPressure,
UnitOfTemperature,
UnitOfTime,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
Expand Down Expand Up @@ -109,6 +110,12 @@ async def create_system_sensors(
index, device_index, system_coordinator
)
)
if device.current_power is not None:
sensors.append(
lambda: SystemDeviceCurrentPowerSensor(
index, device_index, system_coordinator
)
)

for zone_index, zone in enumerate(system.zones):
_LOGGER.debug("Creating Zone sensors for %s", zone)
Expand Down Expand Up @@ -395,9 +402,9 @@ def system(self) -> System:

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
return (
self.system.home.extra_fields | self.system.extra_fields | self.system.rts
)
rts = self.system.rts if self.system.rts else {}
mpc = self.system.mpc if self.system.mpc else {}
return self.system.home.extra_fields | self.system.extra_fields | rts | mpc

@property
def name_prefix(self) -> str:
Expand Down Expand Up @@ -1042,3 +1049,24 @@ def unique_id(self) -> str:
@property
def name(self):
return f"{self.name_prefix} On/Off Cycles"


class SystemDeviceCurrentPowerSensor(SystemDeviceSensor):
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_native_unit_of_measurement = UnitOfPower.WATT

@property
def native_value(self):
if self.device.current_power is not None:
return self.device.current_power
else:
return None

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_current_power"

@property
def name(self):
return f"{self.name_prefix} Current Power"
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ types-PyYAML~=6.0.12.12

# Need specific versions
pytest-homeassistant-custom-component==0.13.101
myPyllant==0.7.25
myPyllant==0.7.26

# Versions handled by pytest-homeassistant-custom-component
freezegun
Expand Down
31 changes: 14 additions & 17 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
SystemTopDHWTemperatureSensor,
SystemBottomDHWTemperatureSensor,
SystemTopCHTemperatureSensor,
SystemDeviceCurrentPowerSensor,
)
from custom_components.mypyllant.const import DOMAIN
from tests.conftest import MockConfigEntry, TEST_OPTIONS
Expand Down Expand Up @@ -246,32 +247,28 @@ async def test_data_sensor(
await mocked_api.aiohttp_session.close()


@pytest.mark.parametrize("test_data", list_test_data())
async def test_device_sensor(
mypyllant_aioresponses,
mocked_api: MyPyllantAPI,
system_coordinator_mock,
test_data,
):
test_data = load_test_data(DATA_DIR / "vrc700_mpc_rts.yaml")
with mypyllant_aioresponses(test_data) as _:
system_coordinator_mock.data = (
await system_coordinator_mock._async_update_data()
)

if "on_off_cycles" in str(test_data):
assert isinstance(
SystemDeviceOnOffCyclesSensor(
0, 0, system_coordinator_mock
).native_value,
int,
)
if "operation_time" in str(test_data):
assert isinstance(
SystemDeviceOperationTimeSensor(
0, 0, system_coordinator_mock
).native_value,
float,
)
assert isinstance(
SystemDeviceOnOffCyclesSensor(0, 0, system_coordinator_mock).native_value,
int,
)
assert isinstance(
SystemDeviceOperationTimeSensor(0, 0, system_coordinator_mock).native_value,
float,
)
assert isinstance(
SystemDeviceCurrentPowerSensor(0, 0, system_coordinator_mock).native_value,
int,
)
await mocked_api.aiohttp_session.close()


Expand Down

0 comments on commit f563792

Please sign in to comment.