Skip to content

Commit

Permalink
fix interpretation of unknown enum and flag values
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Nov 8, 2023
1 parent a119e58 commit b4718c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
9 changes: 7 additions & 2 deletions custom_components/idm_heatpump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"""
from datetime import timedelta

from homeassistant.loader import async_get_integration
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import Config, HomeAssistant
from homeassistant.components import persistent_notification
from homeassistant.const import Platform
from homeassistant.helpers import config_validation as cv
from homeassistant.loader import async_get_integration

from .coordinator import IdmHeatpumpDataUpdateCoordinator
from .idm_heatpump import IdmHeatpump
Expand All @@ -27,10 +28,14 @@
OPT_ZONE_COUNT,
OPT_ZONE_ROOM_9_RELAY,
OPT_ZONE_ROOM_COUNT,
PLATFORMS,
STARTUP_MESSAGE_TEMPLATE,
)

PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.SENSOR,
]

CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)


Expand Down
42 changes: 18 additions & 24 deletions custom_components/idm_heatpump/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from enum import IntFlag, IntEnum
from typing import Any
from homeassistant.const import Platform


class SensorFeatures(IntFlag):
Expand Down Expand Up @@ -32,8 +31,8 @@ class HeatPumpStatus(_SensorFlag):
DEFROSTING = 8

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.OFF
def _missing_(cls, value) -> Any:
return cls.OFF if value is None else None


class IscMode(_SensorFlag):
Expand All @@ -45,8 +44,8 @@ class IscMode(_SensorFlag):
SOURCE = 8

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.NONE
def _missing_(cls, value) -> Any:
return cls.NONE if value is None else None


class CircuitMode(_SensorEnum):
Expand All @@ -60,8 +59,8 @@ class CircuitMode(_SensorEnum):
MANUAL_COOL = 5

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.OFF
def _missing_(cls, value) -> Any:
return cls.OFF if value is None else None


class ActiveCircuitMode(_SensorEnum):
Expand All @@ -72,8 +71,8 @@ class ActiveCircuitMode(_SensorEnum):
COOLING = 2

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.OFF
def _missing_(cls, value) -> Any:
return cls.OFF if value is None else None


class ZoneMode(_SensorEnum):
Expand All @@ -83,8 +82,8 @@ class ZoneMode(_SensorEnum):
HEATING = 1

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.HEATING
def _missing_(cls, value) -> Any:
return cls.HEATING if value is None else None


class RoomMode(_SensorEnum):
Expand All @@ -97,8 +96,8 @@ class RoomMode(_SensorEnum):
COMFORT = 4

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.OFF
def _missing_(cls, value) -> Any:
return cls.OFF if value is None else None


class SystemStatus(_SensorEnum):
Expand All @@ -111,8 +110,8 @@ class SystemStatus(_SensorEnum):
HEATING_COOLING_ONLY = 5

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.STANDBY
def _missing_(cls, value) -> Any:
return cls.STANDBY if value is None else None


class SmartGridStatus(_SensorEnum):
Expand All @@ -124,8 +123,8 @@ class SmartGridStatus(_SensorEnum):
GRID_BLOCKED_SOLAR_ON = 4

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.GRID_BLOCKED_SOLAR_OFF
def _missing_(cls, value) -> Any:
return cls.GRID_BLOCKED_SOLAR_OFF if value is None else None


class SolarMode(_SensorEnum):
Expand All @@ -138,8 +137,8 @@ class SolarMode(_SensorEnum):
SOURCE_POOL = 4

@classmethod
def _missing_(cls, _: object) -> Any:
return cls.AUTO
def _missing_(cls, value) -> Any:
return cls.AUTO if value is None else None


# Base component constants
Expand All @@ -151,11 +150,6 @@ def _missing_(cls, _: object) -> Any:
DOMAIN_DATA = f"{DOMAIN}_data"
ISSUE_URL = "https://github.com/kodebach/hacs-idm-heatpump/issues"

# Platforms
BINARY_SENSOR = Platform.BINARY_SENSOR
SENSOR = Platform.SENSOR
PLATFORMS = [BINARY_SENSOR, SENSOR]

# Services
SERVICE_SET_POWER = "set_power"

Expand Down

0 comments on commit b4718c0

Please sign in to comment.