Skip to content

Commit

Permalink
Merge pull request #8 from gazpachoking/easy_enums
Browse files Browse the repository at this point in the history
  • Loading branch information
bm1549 authored Sep 14, 2021
2 parents 1f3482b + 74d578a commit be5624a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
41 changes: 24 additions & 17 deletions frigidaire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def destination(self) -> str:
raise FrigidaireException(f'Destination field needs to be set for class {self}')


class HaclCode(Enum):
class HaclCode(str, Enum):
CONNECTIVITY_STATE = "0000"
APPLIANCE_SERIAL_NUMBER = "0002"
CONNECTIVITY_NODE_SW_VERSION = "0011"
Expand Down Expand Up @@ -74,7 +74,7 @@ class HaclCode(Enum):
AC_SCHEDULER_EVENT_ONE_TIME = "105A"


class ContainerId(Enum):
class ContainerId(str, Enum):
COEFFICIENT = "1"
EXPONENT = "3"
UNIT = "0"
Expand All @@ -98,7 +98,7 @@ def __init__(self, application_detail_containers: List[ApplianceDetailContainer]
application_detail_containers}

def for_id(self, container_id: ContainerId):
return self.application_detail_containers.get(container_id.value)
return self.application_detail_containers.get(container_id)


class ApplianceDetail:
Expand All @@ -112,13 +112,20 @@ def __init__(self, args: Dict):
self.containers: ApplianceDetailContainers = ApplianceDetailContainers(
list(map(ApplianceDetailContainer, args['containers'])))

def __eq__(self, other):
if isinstance(other, int):
return self.number_value == other
elif isinstance(other, str):
return self.string_value == other
return super().__eq__(other)


class ApplianceDetails:
def __init__(self, appliance_details: List[ApplianceDetail]):
self.appliance_details: Dict = {detail.hacl_code: detail for detail in appliance_details}

def for_code(self, hacl_code: HaclCode) -> Optional[ApplianceDetail]:
return self.appliance_details.get(hacl_code.value)
return self.appliance_details.get(hacl_code)


class Appliance:
Expand Down Expand Up @@ -155,17 +162,17 @@ def __init__(self, name: str, value: Union[int, str]):
dict.__init__(self, name=name, value=value)


class Unit(Enum):
class Unit(str, Enum):
FAHRENHEIT = "Fahrenheit"
CELSIUS = "Celsius"


class Power(Enum):
class Power(int, Enum):
ON = 1
OFF = 0


class Mode(Enum):
class Mode(int, Enum):
# Air Conditioner
OFF = 0
COOL = 1
Expand All @@ -176,7 +183,7 @@ class Mode(Enum):
CONTINUOUS = 8


class FanSpeed(Enum):
class FanSpeed(int, Enum):
# Only HIGH and LOW apply to dehumidifiers
OFF = 0
LOW = 1
Expand All @@ -185,30 +192,30 @@ class FanSpeed(Enum):
AUTO = 7


class ConnectivityState(Enum):
class ConnectivityState(str, Enum):
CONNECTED = 'connect'
DISCONNECTED = 'disconnect'


class Action:
@classmethod
def set_power(cls, power: Power) -> List[Component]:
return [Component(HaclCode.POWER_MODE.value, power.value)]
return [Component(HaclCode.POWER_MODE, power)]

@classmethod
def set_mode(cls, mode: Mode) -> List[Component]:
return [Component(HaclCode.AC_MODE.value, mode.value)]
return [Component(HaclCode.AC_MODE, mode)]

@classmethod
def set_fan_speed(cls, fan_speed: FanSpeed) -> List[Component]:
return [Component(HaclCode.AC_FAN_SPEED_SETTING.value, fan_speed.value)]
return [Component(HaclCode.AC_FAN_SPEED_SETTING, fan_speed)]

@classmethod
def set_humidity(cls, humidity: int) -> List[Component]:
if humidity < 35 or humidity > 85:
raise FrigidaireException("Humidity must be between 35 and 85 percent, inclusive")

return [Component(HaclCode.TARGET_HUMIDITY.value, humidity)]
return [Component(HaclCode.TARGET_HUMIDITY, humidity)]

@classmethod
def set_temperature(cls, temperature: int) -> List[Component]:
Expand All @@ -217,11 +224,11 @@ def set_temperature(cls, temperature: int) -> List[Component]:
raise FrigidaireException("Temperature must be between 60 and 90 degrees, inclusive")

return [
Component(HaclCode.TARGET_TEMPERATURE.value, "Container"),
Component(ContainerId.COEFFICIENT.value, temperature),
Component(HaclCode.TARGET_TEMPERATURE, "Container"),
Component(ContainerId.COEFFICIENT, temperature),
# This is the actual temperature, the rest is some required nonsense
Component(ContainerId.EXPONENT.value, 0),
Component(ContainerId.UNIT.value, 1),
Component(ContainerId.EXPONENT, 0),
Component(ContainerId.UNIT, 1),
]


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='frigidaire',
version='0.14',
version='0.15',
author="Brian Marks",
description="Python API for the Frigidaire 2.0 App",
license="MIT",
Expand Down

0 comments on commit be5624a

Please sign in to comment.