ha_gehome/custom_components/ge_home/devices/fridge.py

103 lines
4.7 KiB
Python
Raw Normal View History

2020-12-29 10:02:56 -07:00
from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
from homeassistant.const import DEVICE_CLASS_TEMPERATURE
import logging
from typing import List
from homeassistant.helpers.entity import Entity
from gehomesdk import (
2020-12-29 10:40:29 -07:00
ErdCode,
ErdApplianceType,
ErdOnOff,
ErdHotWaterStatus,
FridgeIceBucketStatus,
IceMakerControlStatus,
ErdFilterStatus,
2020-12-29 11:18:05 -07:00
HotWaterStatus,
FridgeModelInfo
2020-12-29 10:40:29 -07:00
)
from .base import ApplianceApi
2020-12-29 10:02:56 -07:00
from ..entities import (
2021-02-11 13:07:13 -07:00
GeErdSensor,
GeErdBinarySensor,
2020-12-29 10:02:56 -07:00
GeErdSwitch,
GeFridge,
GeFreezer,
GeDispenser,
GeErdPropertySensor,
GeErdPropertyBinarySensor
)
_LOGGER = logging.getLogger(__name__)
class FridgeApi(ApplianceApi):
"""API class for fridge objects"""
APPLIANCE_TYPE = ErdApplianceType.FRIDGE
def get_all_entities(self) -> List[Entity]:
base_entities = super().get_all_entities()
2020-12-29 10:02:56 -07:00
fridge_entities = []
freezer_entities = []
dispenser_entities = []
2020-12-29 10:40:29 -07:00
# Get the statuses used to determine presence
ice_maker_control: IceMakerControlStatus = self.try_get_erd_value(ErdCode.ICE_MAKER_CONTROL)
ice_bucket_status: FridgeIceBucketStatus = self.try_get_erd_value(ErdCode.ICE_MAKER_BUCKET_STATUS)
water_filter: ErdFilterStatus = self.try_get_erd_value(ErdCode.WATER_FILTER_STATUS)
air_filter: ErdFilterStatus = self.try_get_erd_value(ErdCode.AIR_FILTER_STATUS)
hot_water_status: HotWaterStatus = self.try_get_erd_value(ErdCode.HOT_WATER_STATUS)
fridge_model_info: FridgeModelInfo = self.try_get_erd_value(ErdCode.FRIDGE_MODEL_INFO)
2020-12-29 10:40:29 -07:00
# Common entities
2020-12-29 10:02:56 -07:00
common_entities = [
GeErdSensor(self, ErdCode.FRIDGE_MODEL_INFO),
GeErdSwitch(self, ErdCode.SABBATH_MODE),
2020-12-29 10:02:56 -07:00
GeErdSensor(self, ErdCode.DOOR_STATUS),
GeErdPropertyBinarySensor(self, ErdCode.DOOR_STATUS, "any_open")
]
2020-12-29 10:40:29 -07:00
if(ice_bucket_status and (ice_bucket_status.is_present_fridge or ice_bucket_status.is_present_freezer)):
common_entities.append(GeErdSensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS))
2020-12-29 10:02:56 -07:00
2020-12-29 10:40:29 -07:00
# Fridge entities
if fridge_model_info is None or fridge_model_info.has_fridge:
2020-12-29 11:18:05 -07:00
fridge_entities.extend([
GeErdPropertySensor(self, ErdCode.CURRENT_TEMPERATURE, "fridge"),
GeFridge(self),
])
if(ice_maker_control and ice_maker_control.status_fridge != ErdOnOff.NA):
fridge_entities.append(GeErdPropertyBinarySensor(self, ErdCode.ICE_MAKER_CONTROL, "status_fridge"))
if(water_filter and water_filter != ErdFilterStatus.NA):
fridge_entities.append(GeErdSensor(self, ErdCode.WATER_FILTER_STATUS))
if(air_filter and air_filter != ErdFilterStatus.NA):
fridge_entities.append(GeErdSensor(self, ErdCode.AIR_FILTER_STATUS))
if(ice_bucket_status and ice_bucket_status.is_present_fridge):
fridge_entities.append(GeErdPropertySensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS, "state_full_fridge"))
2020-12-29 10:02:56 -07:00
2020-12-29 10:40:29 -07:00
# Freezer entities
if fridge_model_info is None or fridge_model_info.has_freezer:
2020-12-29 11:18:05 -07:00
freezer_entities.extend([
GeErdPropertySensor(self, ErdCode.CURRENT_TEMPERATURE, "freezer"),
GeFreezer(self),
])
if(ice_maker_control and ice_maker_control.status_freezer != ErdOnOff.NA):
freezer_entities.append(GeErdPropertyBinarySensor(self, ErdCode.ICE_MAKER_CONTROL, "status_freezer"))
2020-12-29 11:18:05 -07:00
if(ice_bucket_status and ice_bucket_status.is_present_freezer):
freezer_entities.append(GeErdPropertySensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS, "state_full_freezer"))
2020-12-29 10:02:56 -07:00
2020-12-29 11:18:05 -07:00
# Dispenser entities
2020-12-29 10:40:29 -07:00
if(hot_water_status and hot_water_status.status != ErdHotWaterStatus.NA):
dispenser_entities.extend([
2021-02-11 13:07:13 -07:00
GeErdBinarySensor(self, ErdCode.HOT_WATER_IN_USE),
2020-12-29 10:40:29 -07:00
GeErdSensor(self, ErdCode.HOT_WATER_SET_TEMP),
2021-07-24 11:17:18 -06:00
GeErdPropertySensor(self, ErdCode.HOT_WATER_STATUS, "status", icon_override="mdi:information-outline"),
GeErdPropertySensor(self, ErdCode.HOT_WATER_STATUS, "time_until_ready", icon_override="mdi:timer-outline"),
2020-12-29 10:40:29 -07:00
GeErdPropertySensor(self, ErdCode.HOT_WATER_STATUS, "current_temp", device_class_override=DEVICE_CLASS_TEMPERATURE),
GeErdPropertyBinarySensor(self, ErdCode.HOT_WATER_STATUS, "faulted", device_class_override=DEVICE_CLASS_PROBLEM),
GeDispenser(self)
])
2020-12-29 10:02:56 -07:00
entities = base_entities + common_entities + fridge_entities + freezer_entities + dispenser_entities
return entities