mirror of https://github.com/simbaja/ha_gehome.git
Merge branch 'dev' of https://github.com/simbaja/ha_components into dev
This commit is contained in:
commit
b77fb6e889
|
@ -6,6 +6,7 @@ import logging
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
|
|
||||||
from gehomesdk import (
|
from gehomesdk import (
|
||||||
ErdCode,
|
ErdCode,
|
||||||
|
@ -26,6 +27,14 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
class GeAbstractFridge(GeAbstractWaterHeater):
|
class GeAbstractFridge(GeAbstractWaterHeater):
|
||||||
"""Mock a fridge or freezer as a water heater."""
|
"""Mock a fridge or freezer as a water heater."""
|
||||||
|
|
||||||
|
# These values are from the Fisher & Paykel RF610AA in imperial units
|
||||||
|
# They're to be used as hardcoded limits when ErdCode.SETPOINT_LIMITS is unavailable.
|
||||||
|
temp_limits = {}
|
||||||
|
temp_limits["fridge_min"] = 32
|
||||||
|
temp_limits["fridge_max"] = 46
|
||||||
|
temp_limits["freezer_min"] = -6
|
||||||
|
temp_limits["freezer_max"] = 7
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def heater_type(self) -> str:
|
def heater_type(self) -> str:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -40,7 +49,11 @@ class GeAbstractFridge(GeAbstractWaterHeater):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operation_list(self) -> List[str]:
|
def operation_list(self) -> List[str]:
|
||||||
return [OP_MODE_NORMAL, OP_MODE_SABBATH, self.turbo_mode]
|
try:
|
||||||
|
return [OP_MODE_NORMAL, OP_MODE_SABBATH, self.turbo_mode]
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("Turbo mode not supported.")
|
||||||
|
return [OP_MODE_NORMAL, OP_MODE_SABBATH]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
|
@ -63,11 +76,15 @@ class GeAbstractFridge(GeAbstractWaterHeater):
|
||||||
@property
|
@property
|
||||||
def current_temperature(self) -> int:
|
def current_temperature(self) -> int:
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
current_temps = self.appliance.get_erd_value(ErdCode.CURRENT_TEMPERATURE)
|
try:
|
||||||
current_temp = getattr(current_temps, self.heater_type)
|
current_temps = self.appliance.get_erd_value(ErdCode.CURRENT_TEMPERATURE)
|
||||||
if current_temp is None:
|
current_temp = getattr(current_temps, self.heater_type)
|
||||||
_LOGGER.exception(f"{self.name} has None for current_temperature (available: {self.available})!")
|
if current_temp is None:
|
||||||
return current_temp
|
_LOGGER.exception(f"{self.name} has None for current_temperature (available: {self.available})!")
|
||||||
|
return current_temp
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("Device doesn't report current temperature.")
|
||||||
|
return None
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
async def async_set_temperature(self, **kwargs):
|
||||||
target_temp = kwargs.get(ATTR_TEMPERATURE)
|
target_temp = kwargs.get(ATTR_TEMPERATURE)
|
||||||
|
@ -95,21 +112,32 @@ class GeAbstractFridge(GeAbstractWaterHeater):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def min_temp(self):
|
||||||
"""Return the minimum temperature."""
|
"""Return the minimum temperature if available, otherwise use hardcoded limits."""
|
||||||
return getattr(self.setpoint_limits, f"{self.heater_type}_min")
|
try:
|
||||||
|
return getattr(self.setpoint_limits, f"{self.heater_type}_min")
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("No temperature setpoint limits available. Using hardcoded limits.")
|
||||||
|
return convert_temperature(self.temp_limits[f"{self.heater_type}_min"], TEMP_FAHRENHEIT, self.temperature_unit)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_temp(self):
|
def max_temp(self):
|
||||||
"""Return the maximum temperature."""
|
"""Return the maximum temperature if available, otherwise use hardcoded limits."""
|
||||||
return getattr(self.setpoint_limits, f"{self.heater_type}_max")
|
try:
|
||||||
|
return getattr(self.setpoint_limits, f"{self.heater_type}_max")
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("No temperature setpoint limits available. Using hardcoded limits.")
|
||||||
|
return convert_temperature(self.temp_limits[f"{self.heater_type}_max"], TEMP_FAHRENHEIT, self.temperature_unit)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_operation(self) -> str:
|
def current_operation(self) -> str:
|
||||||
"""Get the current operation mode."""
|
"""Get the current operation mode."""
|
||||||
if self.appliance.get_erd_value(ErdCode.SABBATH_MODE):
|
if self.appliance.get_erd_value(ErdCode.SABBATH_MODE):
|
||||||
return OP_MODE_SABBATH
|
return OP_MODE_SABBATH
|
||||||
if self.appliance.get_erd_value(self.turbo_erd_code):
|
try:
|
||||||
return self.turbo_mode
|
if self.appliance.get_erd_value(self.turbo_erd_code):
|
||||||
|
return self.turbo_mode
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("Turbo mode not supported.")
|
||||||
return OP_MODE_NORMAL
|
return OP_MODE_NORMAL
|
||||||
|
|
||||||
async def async_set_sabbath_mode(self, sabbath_on: bool = True):
|
async def async_set_sabbath_mode(self, sabbath_on: bool = True):
|
||||||
|
|
|
@ -26,7 +26,10 @@ class GeFreezer(GeAbstractFridge):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def door_state_attrs(self) -> Optional[Dict[str, Any]]:
|
def door_state_attrs(self) -> Optional[Dict[str, Any]]:
|
||||||
door_status = self.door_status.freezer
|
try:
|
||||||
if door_status and door_status != ErdDoorStatus.NA:
|
door_status = self.door_status.freezer
|
||||||
return {ATTR_DOOR_STATUS: self._stringify(door_status)}
|
if door_status and door_status != ErdDoorStatus.NA:
|
||||||
|
return {ATTR_DOOR_STATUS: self._stringify(door_status)}
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("Device does not report door status.")
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -36,23 +36,27 @@ class GeFridge(GeAbstractFridge):
|
||||||
@property
|
@property
|
||||||
def door_state_attrs(self) -> Dict[str, Any]:
|
def door_state_attrs(self) -> Dict[str, Any]:
|
||||||
"""Get state attributes for the doors."""
|
"""Get state attributes for the doors."""
|
||||||
data = {}
|
try:
|
||||||
door_status = self.door_status
|
data = {}
|
||||||
if not door_status:
|
door_status = self.door_status
|
||||||
|
if not door_status:
|
||||||
|
return {}
|
||||||
|
door_right = door_status.fridge_right
|
||||||
|
door_left = door_status.fridge_left
|
||||||
|
drawer = door_status.drawer
|
||||||
|
|
||||||
|
if door_right and door_right != ErdDoorStatus.NA:
|
||||||
|
data["right_door"] = door_status.fridge_right.name.title()
|
||||||
|
if door_left and door_left != ErdDoorStatus.NA:
|
||||||
|
data["left_door"] = door_status.fridge_left.name.title()
|
||||||
|
if drawer and drawer != ErdDoorStatus.NA:
|
||||||
|
data["drawer"] = door_status.drawer.name.title()
|
||||||
|
|
||||||
|
if data:
|
||||||
|
all_closed = all(v == "Closed" for v in data.values())
|
||||||
|
data[ATTR_DOOR_STATUS] = "Closed" if all_closed else "Open"
|
||||||
|
|
||||||
|
return data
|
||||||
|
except:
|
||||||
|
_LOGGER.debug("Device does not report door status.")
|
||||||
return {}
|
return {}
|
||||||
door_right = door_status.fridge_right
|
|
||||||
door_left = door_status.fridge_left
|
|
||||||
drawer = door_status.drawer
|
|
||||||
|
|
||||||
if door_right and door_right != ErdDoorStatus.NA:
|
|
||||||
data["right_door"] = door_status.fridge_right.name.title()
|
|
||||||
if door_left and door_left != ErdDoorStatus.NA:
|
|
||||||
data["left_door"] = door_status.fridge_left.name.title()
|
|
||||||
if drawer and drawer != ErdDoorStatus.NA:
|
|
||||||
data["drawer"] = door_status.drawer.name.title()
|
|
||||||
|
|
||||||
if data:
|
|
||||||
all_closed = all(v == "Closed" for v in data.values())
|
|
||||||
data[ATTR_DOOR_STATUS] = "Closed" if all_closed else "Open"
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
Loading…
Reference in New Issue