2020-12-28 16:36:38 -07:00
|
|
|
"""GE Kitchen Sensor Entities - Dispenser"""
|
2020-12-17 19:20:43 -07:00
|
|
|
|
2020-12-28 16:36:38 -07:00
|
|
|
import logging
|
2020-12-28 20:13:46 -07:00
|
|
|
from typing import List, Optional, Dict, Any
|
|
|
|
|
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_FAHRENHEIT
|
|
|
|
from homeassistant.util.temperature import convert as convert_temperature
|
2020-12-17 19:20:43 -07:00
|
|
|
|
2020-12-29 15:01:29 -07:00
|
|
|
from gekitchensdk import (
|
2020-12-17 19:20:43 -07:00
|
|
|
ErdCode,
|
2020-12-28 20:13:46 -07:00
|
|
|
ErdHotWaterStatus,
|
2020-12-17 19:20:43 -07:00
|
|
|
ErdPresent,
|
2020-12-28 16:36:38 -07:00
|
|
|
ErdPodStatus,
|
2020-12-28 20:13:46 -07:00
|
|
|
ErdFullNotFull,
|
2020-12-17 19:20:43 -07:00
|
|
|
HotWaterStatus
|
|
|
|
)
|
|
|
|
|
2020-12-28 16:36:38 -07:00
|
|
|
from ..common import GeWaterHeater
|
|
|
|
from .const import (
|
2020-12-28 20:13:46 -07:00
|
|
|
HEATER_TYPE_DISPENSER,
|
2020-12-29 07:38:41 -07:00
|
|
|
OP_MODE_NORMAL,
|
2020-12-28 20:13:46 -07:00
|
|
|
OP_MODE_SABBATH,
|
|
|
|
GE_FRIDGE_SUPPORT
|
2020-12-17 19:20:43 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2020-12-28 16:36:38 -07:00
|
|
|
class GeDispenser(GeWaterHeater):
|
|
|
|
"""Entity for in-fridge dispensers"""
|
|
|
|
|
2020-12-28 20:13:46 -07:00
|
|
|
# These values are from FridgeHotWaterFragment.smali in the android app (in imperial units)
|
|
|
|
# However, the k-cup temperature max appears to be 190. Since there doesn't seem to be any
|
|
|
|
# Difference between normal heating and k-cup heating based on what I see in the app,
|
|
|
|
# we will just set the max temp to 190 instead of the 185
|
|
|
|
_min_temp = 90
|
|
|
|
_max_temp = 190 #185
|
|
|
|
icon = "mdi:cup-water"
|
2020-12-28 16:36:38 -07:00
|
|
|
heater_type = HEATER_TYPE_DISPENSER
|
|
|
|
|
2020-12-17 19:20:43 -07:00
|
|
|
@property
|
|
|
|
def hot_water_status(self) -> HotWaterStatus:
|
|
|
|
"""Access the main status value conveniently."""
|
|
|
|
return self.appliance.get_erd_value(ErdCode.HOT_WATER_STATUS)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supports_k_cups(self) -> bool:
|
|
|
|
"""Return True if the device supports k-cup brewing."""
|
|
|
|
status = self.hot_water_status
|
|
|
|
return status.pod_status != ErdPodStatus.NA and status.brew_module != ErdPresent.NA
|
|
|
|
|
|
|
|
@property
|
|
|
|
def operation_list(self) -> List[str]:
|
|
|
|
"""Supported Operations List"""
|
2020-12-29 07:38:41 -07:00
|
|
|
ops_list = [OP_MODE_NORMAL, OP_MODE_SABBATH]
|
2020-12-17 19:20:43 -07:00
|
|
|
return ops_list
|
|
|
|
|
|
|
|
async def async_set_temperature(self, **kwargs):
|
2020-12-28 20:13:46 -07:00
|
|
|
target_temp = kwargs.get(ATTR_TEMPERATURE)
|
|
|
|
if target_temp is None:
|
|
|
|
return
|
|
|
|
if not self.min_temp <= target_temp <= self.max_temp:
|
|
|
|
raise ValueError("Tried to set temperature out of device range")
|
|
|
|
|
|
|
|
await self.appliance.async_set_erd_value(ErdCode.HOT_WATER_SET_TEMP, target_temp)
|
|
|
|
|
|
|
|
async def async_set_sabbath_mode(self, sabbath_on: bool = True):
|
|
|
|
"""Set sabbath mode if it's changed"""
|
|
|
|
if self.appliance.get_erd_value(ErdCode.SABBATH_MODE) == sabbath_on:
|
|
|
|
return
|
|
|
|
await self.appliance.async_set_erd_value(ErdCode.SABBATH_MODE, sabbath_on)
|
2020-12-17 19:20:43 -07:00
|
|
|
|
|
|
|
async def async_set_operation_mode(self, operation_mode):
|
2020-12-28 20:13:46 -07:00
|
|
|
"""Set the operation mode."""
|
|
|
|
if operation_mode not in self.operation_list:
|
|
|
|
raise ValueError("Invalid operation mode")
|
|
|
|
if operation_mode == self.current_operation:
|
|
|
|
return
|
|
|
|
sabbath_mode = operation_mode == OP_MODE_SABBATH
|
|
|
|
await self.async_set_sabbath_mode(sabbath_mode)
|
2020-12-17 19:20:43 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
2020-12-28 20:13:46 -07:00
|
|
|
return GE_FRIDGE_SUPPORT
|
2020-12-17 19:20:43 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_operation(self) -> str:
|
|
|
|
"""Get the current operation mode."""
|
|
|
|
if self.appliance.get_erd_value(ErdCode.SABBATH_MODE):
|
|
|
|
return OP_MODE_SABBATH
|
2020-12-29 07:38:41 -07:00
|
|
|
return OP_MODE_NORMAL
|
2020-12-17 19:20:43 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self) -> Optional[int]:
|
|
|
|
"""Return the current temperature."""
|
|
|
|
return self.hot_water_status.current_temp
|
2020-12-28 20:13:46 -07:00
|
|
|
|
2020-12-29 07:38:41 -07:00
|
|
|
@property
|
|
|
|
def target_temperature(self) -> Optional[int]:
|
|
|
|
"""Return the target temperature."""
|
|
|
|
return self.appliance.get_erd_value(ErdCode.HOT_WATER_SET_TEMP)
|
|
|
|
|
2020-12-28 20:13:46 -07:00
|
|
|
@property
|
|
|
|
def min_temp(self):
|
|
|
|
"""Return the minimum temperature."""
|
|
|
|
return convert_temperature(self._min_temp, TEMP_FAHRENHEIT, self.temperature_unit)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self):
|
|
|
|
"""Return the maximum temperature."""
|
|
|
|
return convert_temperature(self._max_temp, TEMP_FAHRENHEIT, self.temperature_unit)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def other_state_attrs(self) -> Dict[str, Any]:
|
|
|
|
data = {}
|
2020-12-29 07:38:41 -07:00
|
|
|
|
|
|
|
data["target_temperature"] = self.target_temperature
|
2020-12-28 20:13:46 -07:00
|
|
|
if self.hot_water_status.status in [ErdHotWaterStatus.FAULT_LOCKED_OUT, ErdHotWaterStatus.FAULT_NEED_CLEARED]:
|
2020-12-29 08:03:37 -07:00
|
|
|
data["fault_status"] = self._stringify(self.hot_water_status.status)
|
2020-12-28 20:13:46 -07:00
|
|
|
if self.supports_k_cups:
|
2020-12-29 08:03:37 -07:00
|
|
|
data["pod_status"] = self._stringify(self.hot_water_status.pod_status)
|
2020-12-28 20:13:46 -07:00
|
|
|
if self.hot_water_status.time_until_ready:
|
2020-12-29 08:03:37 -07:00
|
|
|
data["time_until_ready"] = self._stringify(self.hot_water_status.time_until_ready)
|
2020-12-28 20:13:46 -07:00
|
|
|
if self.hot_water_status.tank_full != ErdFullNotFull.NA:
|
2020-12-29 08:03:37 -07:00
|
|
|
data["tank_status"] = self._stringify(self.hot_water_status.tank_full)
|