Skip to content

Commit

Permalink
Remove __json__ boilerplate code from all status containers (rytilaht…
Browse files Browse the repository at this point in the history
…i#827)

All implementations were simply returning the `data` for this request,
and forgetting to add this boilerplate piece causes problems like shown in rytilahti#816.

This commit adds a lookup for `data` variable which should be consistent within all containers.
For the time being, this behavior can still be overridden by manually defining __json__.

Fixes rytilahti#816
  • Loading branch information
rytilahti authored and xvlady committed May 9, 2021
1 parent adb25a1 commit c33e7cf
Show file tree
Hide file tree
Showing 32 changed files with 3 additions and 123 deletions.
3 changes: 0 additions & 3 deletions miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirConditioningCompanion(Device):
"""Main class representing Xiaomi Air Conditioning Companion V1 and V2."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airconditioningcompanionMCN.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirConditioningCompanionMcn02(Device):
"""Main class representing Xiaomi Air Conditioning Companion V1 and V2."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airdehumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirDehumidifier(Device):
"""Implementation of Xiaomi Mi Air Dehumidifier."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airfresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirFresh(Device):
"""Main class representing the air fresh."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airfresh_t2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirFreshT2017(Device):
"""Main class representing the air fresh t2017."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirHumidifier(Device):
"""Implementation of Xiaomi Mi Air Humidifier."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airhumidifier_jsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirHumidifierJsq(Device):
"""
Expand Down
3 changes: 0 additions & 3 deletions miio/airhumidifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirHumidifierMiot(MiotDevice):
"""Main class representing the air humidifier which uses MIoT protocol."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirHumidifierMjjsq(Device):
def __init__(
Expand Down
3 changes: 0 additions & 3 deletions miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirPurifier(Device):
"""Main class representing the air purifier."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airpurifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirPurifierMiot(MiotDevice):
"""Main class representing the air purifier which uses MIoT protocol."""
Expand Down
3 changes: 0 additions & 3 deletions miio/airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AirQualityMonitor(Device):
"""Xiaomi PM2.5 Air Quality Monitor."""
Expand Down
3 changes: 0 additions & 3 deletions miio/aqaracamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class AqaraCamera(Device):
"""Main class representing the Xiaomi Aqara Camera."""
Expand Down
3 changes: 0 additions & 3 deletions miio/ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class Ceil(Device):
"""Main class representing Xiaomi Philips LED Ceiling Lamp."""
Expand Down
3 changes: 0 additions & 3 deletions miio/chuangmi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class ChuangmiCamera(Device):
"""Main class representing the Xiaomi Chuangmi Camera."""
Expand Down
3 changes: 0 additions & 3 deletions miio/chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class ChuangmiPlug(Device):
"""Main class representing the Chuangmi Plug."""
Expand Down
3 changes: 3 additions & 0 deletions miio/click_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,11 @@ def wrap(*args, **kwargs):
return

get_json_data_func = getattr(result, "__json__", None)
data_variable = getattr(result, "data", None)
if get_json_data_func is not None:
result = get_json_data_func()
elif data_variable is not None:
result = data_variable
click.echo(json.dumps(result, indent=indent))

return wrap
Expand Down
3 changes: 0 additions & 3 deletions miio/cooker.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ def __repr__(self) -> str:
s = "<TemperatureHistory temperatures=%s>" % str(self.data)
return s

def __json__(self):
return self.data


class CookerCustomizations:
def __init__(self, custom: str):
Expand Down
3 changes: 0 additions & 3 deletions miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ def __repr__(self):
self.data["token"],
)

def __json__(self):
return self.data

@property
def network_interface(self):
"""Information about network configuration."""
Expand Down
6 changes: 0 additions & 6 deletions miio/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class FanStatusP5:
"""Container for status reports from the Xiaomi Mi Smart Pedestal Fan DMaker P5."""
Expand Down Expand Up @@ -363,9 +360,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class Fan(Device):
"""Main class representing the Xiaomi Mi Smart Pedestal Fan."""
Expand Down
3 changes: 0 additions & 3 deletions miio/heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class Heater(Device):
"""Main class representing the Smartmi Zhimi Heater."""
Expand Down
3 changes: 0 additions & 3 deletions miio/philips_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PhilipsWhiteBulb(Device):
"""Main class representing Xiaomi Philips White LED Ball Lamp."""
Expand Down
3 changes: 0 additions & 3 deletions miio/philips_eyecare.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PhilipsEyecare(Device):
"""Main class representing Xiaomi Philips Eyecare Smart Lamp 2."""
Expand Down
3 changes: 0 additions & 3 deletions miio/philips_moonlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PhilipsMoonlight(Device):
"""Main class representing Xiaomi Philips Zhirui Bedside Lamp.
Expand Down
3 changes: 0 additions & 3 deletions miio/philips_rwread.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PhilipsRwread(Device):
"""Main class representing Xiaomi Philips RW Read."""
Expand Down
3 changes: 0 additions & 3 deletions miio/powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PowerStrip(Device):
"""Main class representing the smart power strip."""
Expand Down
3 changes: 0 additions & 3 deletions miio/pwzn_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ def __repr__(self) -> str:
)
return s

def __json__(self):
return self.data


class PwznRelay(Device):
"""Main class representing the PWZN Relay."""
Expand Down
27 changes: 0 additions & 27 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ def __repr__(self) -> str:
s += "cleaned %s m² in %s>" % (self.clean_area, self.clean_time)
return s

def __json__(self):
return self.data


class CleaningSummary:
"""Contains summarized information about available cleaning runs."""
Expand Down Expand Up @@ -228,9 +225,6 @@ def __repr__(self) -> str:
% (self.count, self.total_duration, self.total_area, self.ids) # noqa: E501
)

def __json__(self):
return self.data


class CleaningDetails:
"""Contains details about a specific cleaning run."""
Expand Down Expand Up @@ -285,9 +279,6 @@ def __repr__(self) -> str:
self.area,
)

def __json__(self):
return self.data


class ConsumableStatus:
"""Container for consumable status information,
Expand Down Expand Up @@ -361,9 +352,6 @@ def __repr__(self) -> str:
)
)

def __json__(self):
return self.data


class DNDStatus:
"""A container for the do-not-disturb status."""
Expand Down Expand Up @@ -395,9 +383,6 @@ def __repr__(self):
self.end,
)

def __json__(self):
return self.data


class Timer:
"""A container for scheduling.
Expand Down Expand Up @@ -454,9 +439,6 @@ def __repr__(self) -> str:
self.cron,
)

def __json__(self):
return self.data


class SoundStatus:
"""Container for sound status."""
Expand All @@ -479,9 +461,6 @@ def __repr__(self):
self.being_installed,
)

def __json__(self):
return self.data


class SoundInstallState(IntEnum):
Unknown = 0
Expand Down Expand Up @@ -544,9 +523,6 @@ def __repr__(self) -> str:
" - progress: %s>" % (self.sid, self.state, self.error, self.progress)
)

def __json__(self):
return self.data


class CarpetModeStatus:
"""Container for carpet mode status."""
Expand Down Expand Up @@ -590,6 +566,3 @@ def __repr__(self):
self.current_integral,
)
)

def __json__(self):
return self.data
3 changes: 0 additions & 3 deletions miio/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ def __repr__(self) -> str:
)
)

def __json__(self):
return self.data


class ViomiVacuumSpeed(Enum):
Silent = 0
Expand Down
3 changes: 0 additions & 3 deletions miio/waterpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ def __repr__(self) -> str:
)
)

def __json__(self):
return self.data


class WaterPurifier(Device):
"""Main class representing the waiter purifier."""
Expand Down
Loading

0 comments on commit c33e7cf

Please sign in to comment.