Skip to content

Commit

Permalink
Do not get battery status for mains powered devices (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Sep 5, 2021
1 parent 981368c commit 9ad62be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
19 changes: 17 additions & 2 deletions miio/gateway/devices/subdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
if model_info is None:
model_info = {}
self._model_info = model_info
self._battery_powered = model_info.get("battery_powered", True)
self._battery = None
self._voltage = None
self._fw_ver = dev_info.fw_ver
Expand Down Expand Up @@ -206,8 +207,15 @@ def unpair(self):
return self.send("remove_device")

@command()
def get_battery(self):
def get_battery(self) -> Optional[int]:
"""Update the battery level, if available."""
if not self._battery_powered:
_LOGGER.debug(
"%s is not battery powered, get_battery not supported",
self.name,
)
return None

if self._gw.model not in [GATEWAY_MODEL_EU, GATEWAY_MODEL_ZIG3]:
self._battery = self.send("get_battery").pop()
else:
Expand All @@ -218,8 +226,15 @@ def get_battery(self):
return self._battery

@command()
def get_voltage(self):
def get_voltage(self) -> Optional[float]:
"""Update the battery voltage, if available."""
if not self._battery_powered:
_LOGGER.debug(
"%s is not battery powered, get_voltage not supported",
self.name,
)
return None

if self._gw.model in [GATEWAY_MODEL_EU, GATEWAY_MODEL_ZIG3]:
self._voltage = self.get_property("voltage").pop() / 1000
else:
Expand Down
21 changes: 21 additions & 0 deletions miio/gateway/devices/subdevices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
name: Smart bulb E27
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -152,6 +153,7 @@
name: Ikea smart bulb E27 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -177,6 +179,7 @@
name: Ikea smart bulb E27 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -202,6 +205,7 @@
name: Ikea smart bulb E12 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -227,6 +231,7 @@
name: Ikea smart bulb GU10 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -252,6 +257,7 @@
name: Ikea smart bulb E27 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -277,6 +283,7 @@
name: Ikea smart bulb GU10 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand All @@ -302,6 +309,7 @@
name: Ikea smart bulb E12 white
type: LightBulb
class: LightBulb
battery_powered: false
properties:
- property: power_status # 'on' / 'off'
name: status
Expand Down Expand Up @@ -474,6 +482,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -489,6 +498,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -501,6 +511,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -516,6 +527,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -534,6 +546,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -549,6 +562,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -567,6 +581,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -588,6 +603,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -610,6 +626,7 @@
class: Switch
getter: get_prop_plug
setter: toggle_plug
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -626,6 +643,7 @@
class: Switch
getter: get_prop_plug
setter: toggle_plug
battery_powered: false
properties:
- property: neutral_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -641,6 +659,7 @@
type: Switch
class: Switch
setter: toggle_plug
battery_powered: false
properties:
- property: channel_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -653,6 +672,7 @@
type: Switch
class: Switch
setter: toggle_plug
battery_powered: false
properties:
- property: channel_0 # 'on' / 'off'
name: status_ch0
Expand All @@ -668,6 +688,7 @@
type: Switch
class: Switch
setter: toggle_ctrl_neutral
battery_powered: false
properties:
- property: channel_0 # 'on' / 'off'
name: status_ch0
Expand Down

0 comments on commit 9ad62be

Please sign in to comment.