Merge pull request #63 from alexanv1/dev

Fixes for CoffeeMaker support
This commit is contained in:
simbaja 2021-12-13 09:32:24 -05:00 committed by GitHub
commit a2fa673b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -25,6 +25,8 @@ class CcmApi(ApplianceApi):
def get_all_entities(self) -> List[Entity]:
base_entities = super().get_all_entities()
units = self.hass.config.units
ccm_entities = [
GeErdBinarySensor(self, ErdCode.CCM_IS_BREWING, device_class_override="heat"),
GeErdBinarySensor(self, ErdCode.CCM_IS_DESCALING),
@ -34,7 +36,7 @@ class CcmApi(ApplianceApi):
GeErdSensor(self, ErdCode.CCM_CURRENT_WATER_TEMPERATURE),
GeErdBinarySensor(self, ErdCode.CCM_OUT_OF_WATER, device_class_override="problem"),
GeCcmPotNotPresentBinarySensor(self, ErdCode.CCM_POT_PRESENT, device_class_override="problem"),
GeCcm(self)
GeCcm(self, units)
]
entities = base_entities + ccm_entities

View File

@ -11,6 +11,7 @@ from gehomesdk import (
)
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.util.unit_system import UnitSystem
from ...const import DOMAIN
from ...devices import ApplianceApi
@ -25,9 +26,9 @@ class GeCcm(GeWaterHeater):
icon = "mdi:coffee-maker"
def __init__(self, api: ApplianceApi):
def __init__(self, api: ApplianceApi, units: UnitSystem):
super().__init__(api)
self._options = CcmBrewOptionsConverter()
self._options = CcmBrewOptionsConverter(units)
@property
def supported_features(self):
@ -122,7 +123,7 @@ class GeCcm(GeWaterHeater):
try:
if operation_mode not in ["Off","Descale"]:
new_mode = self._options.from_option_string(operation_mode)
new_mode.brew_temperature = self.target_temperature
new_mode = ErdCcmBrewSettings(new_mode.number_of_cups, new_mode.brew_strength, self.target_temperature)
await self.appliance.async_set_erd_value(ErdCode.CCM_BREW_SETTINGS, new_mode)
elif operation_mode == "Off":
@ -131,7 +132,7 @@ class GeCcm(GeWaterHeater):
elif operation_mode == "Descale":
await self.appliance.async_set_erd_value(ErdCode.CCM_START_DESCALING, True)
except:
_LOGGER.debug(f"Error Attempting to set mode to {operation_mode}.")
_LOGGER.error(f"Error Attempting to set mode to {operation_mode}.", exc_info=True)
async def async_set_temperature(self, **kwargs):
"""Set the brew temperature"""

View File

@ -25,20 +25,22 @@ class CcmBrewOptionsConverter(OptionsConverter):
@property
def options(self) -> List[str]:
return (
["Off"]
.extend([i.stringify() for i in self._options])
.extend("Descale")
)
options = ["Off"]
options.extend([i.stringify() for i in self._options])
options.extend(["Descale"])
return options
def from_option_string(self, value: str) -> Optional[ErdCcmBrewSettings]:
try:
if value in ["Off","Descale"]:
return None
s = value.split(" -- ")[0]
s = value.split(" -- ")[0].upper()
c = value.split(" -- ")[1].replace(" cups","")
return ErdCcmBrewSettings(int(c), ErdCcmBrewStrength(s), 200)
return ErdCcmBrewSettings(int(c), ErdCcmBrewStrength[s], 200)
except:
_LOGGER.error(f"Could not convert brew options '{value}'", exc_info=True)
#return a default if we can't interpret it
return ErdCcmBrewSettings(4, ErdCcmBrewStrength.MEDIUM, 200)
@ -52,7 +54,8 @@ class CcmBrewOptionsConverter(OptionsConverter):
def _build_options(self) -> List[CcmBrewOption]:
options = []
for s in ErdCcmBrewStrength:
for s in filter(lambda x: x != ErdCcmBrewStrength.UNKNOWN, ErdCcmBrewStrength):
for c in range(MIN_CUPS, MAX_CUPS, 2):
options.append(CcmBrewOption(s, c))
return options