Skip to content

Commit

Permalink
Add test for HM-CC-VG-1 (HM-Heatinggroup) (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Jan 13, 2022
1 parent 02a2970 commit 9383933
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version 0.20.1 (2022-01-13)
- Remove typecast for text, binary_sensor and number
- Don't exclude Servicemeldungen from sysvars
- Use Servicemeldungen sysvar for hub state
- Add test for HM-CC-VG-1 (HM-Heatinggroup)

Version 0.20.0 (2022-01-12)
- Add converter to BaseParameterEntity/GenericEntity
Expand Down
23 changes: 3 additions & 20 deletions hahomematic/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from typing import Any

from hahomematic.const import ATTR_HM_MAX, ATTR_HM_MIN, HmPlatform
from hahomematic.const import HmPlatform
import hahomematic.device as hm_device
from hahomematic.devices.entity_definition import (
FIELD_ACTIVE_PROFILE,
Expand Down Expand Up @@ -114,20 +114,12 @@ def temperature_unit(self) -> str:
@property
def min_temp(self) -> float:
"""Return the minimum temperature."""
return self._get_entity_attribute(
field_name=FIELD_SETPOINT,
attr_name=ATTR_HM_MIN.lower(),
default=HM_MIN_VALUE,
)
return self._e_setpoint.min

@property
def max_temp(self) -> float:
"""Return the maximum temperature."""
return self._get_entity_attribute(
field_name=FIELD_SETPOINT,
attr_name=ATTR_HM_MAX.lower(),
default=HM_MAX_VALUE,
)
return self._e_setpoint.max

@property
def target_temperature_step(self) -> float:
Expand Down Expand Up @@ -207,15 +199,6 @@ async def disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""
return None

def _get_entity_attribute(
self, field_name: str, attr_name: str, default: float
) -> float:
"""get entity attribute value"""
entity = self.data_entities.get(field_name)
if entity and hasattr(entity, attr_name):
return float(getattr(entity, attr_name))
return default


class CeSimpleRfThermostat(BaseClimateEntity):
"""Simple classic HomeMatic thermostat HM-CC-TC."""
Expand Down
1 change: 1 addition & 0 deletions hahomematic/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

SERVICE_MESSAGES = "Servicemeldungen"


class BaseHubEntity(ABC):
"""
Base class for hub entities.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def readme():
},
PACKAGE_NAME = "hahomematic"
HERE = os.path.abspath(os.path.dirname(__file__))
VERSION = "0.20.1"
VERSION = "0.21.0"

PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"])

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def get_hm_custom_entity(
"""Return the hm custom_entity."""
hm_device = get_hm_device(central_unit, address)
assert hm_device
for custom_entity in hm_device.custom_entities:
for custom_entity in hm_device.custom_entities.values():
if custom_entity.channel_no == channel_no:
if do_load:
await custom_entity.load_data()
Expand Down
38 changes: 33 additions & 5 deletions tests/test_central.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Test the HaHomematic central."""
from typing import Any
from unittest.mock import patch
from hahomematic.const import HmPlatform
from conftest import get_value_from_generic_entity, send_device_value_to_ccu, get_hm_device
from conftest import (
get_hm_custom_entity,
get_hm_device,
get_hm_genertic_entity,
get_value_from_generic_entity,
send_device_value_to_ccu,
)
import pytest

from hahomematic.helpers import get_device_address
from hahomematic.devices.climate import ATTR_TEMPERATURE, CeRfThermostat


@pytest.mark.asyncio
Expand Down Expand Up @@ -69,6 +72,7 @@ async def test_device_set_data(central, pydev_ccu, loop) -> None:
)
assert new_value == 19.0


@pytest.mark.asyncio
async def test_device_export(central, pydev_ccu, loop) -> None:
"""Test device export."""
Expand All @@ -78,10 +82,34 @@ async def test_device_export(central, pydev_ccu, loop) -> None:
assert hm_device
await hm_device.export_device_definition()


@pytest.mark.asyncio
async def test_all_parameters(central, pydev_ccu, loop) -> None:
"""Test device export."""
assert central
assert pydev_ccu
parameters = central.paramsets.get_all_parameters()
assert parameters


@pytest.mark.asyncio
async def test_device_hm_heatgroup(central, pydev_ccu, loop) -> None:
"""Test callback."""
assert central
assert pydev_ccu
entity = await get_hm_genertic_entity(central, "INT0000001:1", "SET_TEMPERATURE")
old_value = entity.value
assert old_value is None

custom_entity: CeRfThermostat = await get_hm_custom_entity(central, "INT0000001", 1)
assert custom_entity.current_temperature is None
kwargs = {ATTR_TEMPERATURE: 19.0}
await custom_entity.set_temperature(**kwargs)

new_value = await get_value_from_generic_entity(
central, "INT0000001:1", "SET_TEMPERATURE"
)
assert new_value == 19.0
assert custom_entity._e_setpoint.value == 19.0
assert custom_entity.target_temperature == 19.0

0 comments on commit 9383933

Please sign in to comment.