Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure and improve gateway subdevices #700

Merged
merged 35 commits into from
May 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ae6f351
restructure and improve gateway subdevices
starkillerOG May 20, 2020
5f1cf14
Update gateway.py
starkillerOG May 23, 2020
dbf986d
fix cli
starkillerOG May 23, 2020
8ffb765
black formatting
starkillerOG May 23, 2020
692ebfc
filter out gateway
starkillerOG May 23, 2020
c4c0699
better error handeling
starkillerOG May 23, 2020
581dcb3
common GatewayDevice class for __init__
starkillerOG May 23, 2020
27a89d3
remove duplicate "gateway" from method name
starkillerOG May 23, 2020
d18c65f
use device_type instead of device_name for mapping
starkillerOG May 23, 2020
a21e381
add comments
starkillerOG May 23, 2020
064ffe8
use DeviceType.Gateway
starkillerOG May 23, 2020
96efd88
Update gateway.py
starkillerOG May 23, 2020
651664f
improve discovered info
starkillerOG May 23, 2020
25e52e6
fix formatting
starkillerOG May 23, 2020
d4da84e
better use of dev_info
starkillerOG May 23, 2020
b2bb69d
final black formatting
starkillerOG May 23, 2020
194a57a
process revieuw
starkillerOG May 24, 2020
e85b885
generilize properties of subdevices
starkillerOG May 24, 2020
040e2c1
Subdevice schould not derive from Device
starkillerOG May 24, 2020
fc8f8a7
simplify dataclass props for subdevices
starkillerOG May 26, 2020
1f016ab
optimization
starkillerOG May 26, 2020
2b471c2
remove empty checks and futher simplify dataclass
starkillerOG May 26, 2020
2b7e1b7
Update gateway.py
starkillerOG May 26, 2020
9a4eef7
add back SensorHT
starkillerOG May 26, 2020
f73b167
add back Empty response
starkillerOG May 26, 2020
8b84163
black formatting
starkillerOG May 26, 2020
91fb301
add missing docstrings
starkillerOG May 26, 2020
630ade9
fix except
starkillerOG May 26, 2020
f25a726
fix black
starkillerOG May 26, 2020
b6104d1
Update pyproject.toml
starkillerOG May 26, 2020
a114386
Update pyproject.toml
starkillerOG May 26, 2020
e99accb
fix dataclasses
starkillerOG May 26, 2020
eaba358
replace dataclasses by attr
starkillerOG May 27, 2020
0ab1dc7
add get_local_status command
starkillerOG May 27, 2020
0f05432
remove local.status again
starkillerOG May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions miio/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,33 @@ def discover_devices(self):
"""Discovers SubDevices and returns a list of the discovered devices."""
# from https://github.com/aholstenson/miio/issues/26
device_type_mapping = {
"AqaraRelayTwoChannels": AqaraRelayTwoChannels,
"Plug": AqaraPlug,
"SensorHT": SensorHT,
"AqaraHT": AqaraHT,
"AqaraMagnet": AqaraMagnet,
DeviceType.AqaraRelayTwoChannels: AqaraRelayTwoChannels,
DeviceType.Plug: AqaraPlug,
DeviceType.SensorHT: SensorHT,
DeviceType.AqaraHT: AqaraHT,
DeviceType.AqaraMagnet: AqaraMagnet,
}
devices_raw = self.get_prop("device_list")
self._devices = []

for x in range(0, len(devices_raw), 5):
starkillerOG marked this conversation as resolved.
Show resolved Hide resolved
starkillerOG marked this conversation as resolved.
Show resolved Hide resolved
try:
device_name = DeviceType(devices_raw[x + 1]).name
device_type = DeviceType(devices_raw[x + 1])
except ValueError:
_LOGGER.warning(
"Unknown subdevice type '%i': %s discovered, of Xiaomi gateway with ip: %s",
devices_raw[x + 1],
devices_raw[x],
self.ip,
)
device_name = DeviceType(-1).name
device_type = DeviceType(-1)

subdevice_cls = device_type_mapping.get(device_name)
if subdevice_cls is None and device_name != DeviceType(0).name:
subdevice_cls = device_type_mapping.get(device_type)
if subdevice_cls is None and device_type != DeviceType(0):
starkillerOG marked this conversation as resolved.
Show resolved Hide resolved
subdevice_cls = SubDevice
_LOGGER.info(
"Gateway device type '%s' does not have device specific methods defined, only basic default methods will be available",
device_name,
device_type.name,
)

if devices_raw[x] != "lumi.0":
starkillerOG marked this conversation as resolved.
Show resolved Hide resolved
Expand Down