Skip to content

Commit

Permalink
Use generic climate profiles list (#131)
Browse files Browse the repository at this point in the history
* Use generic climate profiles list

* Check for None on Cover
  • Loading branch information
SukramJ authored Jan 4, 2022
1 parent e8774e0 commit 905cfb7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 0.13.1 (2022-01-04)
- Use generic climate profiles list

Version 0.13.0 (2022-01-04)
- Remove dedicated json tls option
- Fix unique_id for heating_groups
Expand Down
35 changes: 15 additions & 20 deletions hahomematic/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
SUPPORT_TARGET_TEMPERATURE = 1
SUPPORT_PRESET_MODE = 16

HEATING_PROFILES = {"Profile 1": 1, "Profile 2": 2, "Profile 3": 3}
COOLING_PROFILES = {"Profile 4": 4, "Profile 5": 5, "Profile 6": 6}
HM_MIN_VALUE = 4.5
HM_MAX_VALUE = 30.5

Expand Down Expand Up @@ -430,9 +428,10 @@ async def set_preset_mode(self, preset_mode: str) -> None:
if preset_mode in self._profile_names:
if self.hvac_mode != HVAC_MODE_AUTO:
await self.set_hvac_mode(HVAC_MODE_AUTO)
profile_idx = self._get_profile_idx_by_name(preset_mode)
profile_idx = self._profiles.get(preset_mode)
await self._e_boost_mode.send_value(False)
await self._e_active_profile.send_value(profile_idx)
if profile_idx:
await self._e_active_profile.send_value(profile_idx)

async def enable_away_mode_by_calendar(
self, start: datetime, end: datetime, away_temperature: float
Expand Down Expand Up @@ -477,28 +476,24 @@ async def disable_away_mode(self) -> None:
@property
def _profile_names(self) -> list[str]:
"""Return a collection of profile names."""
return list(self._relevant_profiles.keys())
return list(self._profiles.keys())

@property
def _current_profile_name(self) -> str | None:
"""Return a profile index by name."""
inv_profiles: dict[int, str] = {
v: k for k, v in self._relevant_profiles.items()
}
return (
inv_profiles[int(self._e_active_profile.value)]
if self._e_active_profile.value is not None
else None
)

def _get_profile_idx_by_name(self, profile_name: str) -> int:
"""Return a profile index by name."""
return self._relevant_profiles[profile_name]
inv_profiles: dict[int, str] = {v: k for k, v in self._profiles.items()}
if self._e_active_profile.value:
return inv_profiles.get(int(self._e_active_profile.value))
return None

@property
def _relevant_profiles(self) -> dict[str, int]:
"""Return the relevant profile groups."""
return HEATING_PROFILES if self._is_heating else COOLING_PROFILES
def _profiles(self) -> dict[str, int]:
"""Return the profile groups."""
profiles: dict[str, int] = {}
for i in range(self._e_active_profile.min, self._e_active_profile.max+1):
profiles[f"Profile {i}"] = i

return profiles


def make_simple_thermostat(
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _e_stop(self) -> HmAction:
def _channel_level(self) -> float | None:
"""Return the channel level of the cover."""
channel_level = self._get_entity_value(field_name=FIELD_CHANNEL_LEVEL)
if channel_level:
if channel_level is not None:
return float(channel_level)
return self._e_level.value

Expand Down Expand Up @@ -146,7 +146,7 @@ def _e_level_2(self) -> HmFloat:
def _channel_level_2(self) -> float | None:
"""Return the channel level of the tilt."""
channel_level_2 = self._get_entity_value(field_name=FIELD_CHANNEL_LEVEL_2)
if channel_level_2:
if channel_level_2 is not None:
return float(channel_level_2)
return self._e_level_2.value

Expand Down
7 changes: 7 additions & 0 deletions hahomematic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,14 @@ def fix_unit(unit: str | None) -> str | None:
class NoneTypeEntity:
"""Entity to return an empty value."""

default: Any = None
hmtype: Any = None
max: Any = None
min: Any = None
unit: Any = None
value: Any = None
value_list: list[Any] = []
visible: Any = None

def send_value(self, value: Any) -> None:
"""Dummy method."""
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.13.0"
VERSION = "0.13.1"

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

Expand Down

0 comments on commit 905cfb7

Please sign in to comment.