Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b346f766f | |||
f52f84711f | |||
c4d21be388 |
@ -24,6 +24,7 @@ def get_arguments():
|
|||||||
subparser = parser.add_subparsers(title="commands", metavar="COMMAND")
|
subparser = parser.add_subparsers(title="commands", metavar="COMMAND")
|
||||||
keys = subparser.add_parser("keys", help="print as key format")
|
keys = subparser.add_parser("keys", help="print as key format")
|
||||||
keys.add_argument("keys", help="print as key format", action="store_true")
|
keys.add_argument("keys", help="print as key format", action="store_true")
|
||||||
|
keys.add_argument("--all", help="print also full keys", action="store_true")
|
||||||
return vars(parser.parse_args())
|
return vars(parser.parse_args())
|
||||||
|
|
||||||
|
|
||||||
@ -90,9 +91,12 @@ async def main():
|
|||||||
for device in hon.devices:
|
for device in hon.devices:
|
||||||
print("=" * 10, device.appliance_type, "-", device.nick_name, "=" * 10)
|
print("=" * 10, device.appliance_type, "-", device.nick_name, "=" * 10)
|
||||||
if args.get("keys"):
|
if args.get("keys"):
|
||||||
key_print(device.data["attributes"]["parameters"])
|
data = device.data.copy()
|
||||||
key_print(device.data["appliance"])
|
attr = "get" if args.get("all") else "pop"
|
||||||
key_print(device.data)
|
key_print(data["attributes"].__getattribute__(attr)("parameters"))
|
||||||
|
key_print(data.__getattribute__(attr)("appliance"))
|
||||||
|
key_print(data.__getattribute__(attr)("commands"))
|
||||||
|
key_print(data)
|
||||||
pretty_print(create_command(device.commands, concat=True))
|
pretty_print(create_command(device.commands, concat=True))
|
||||||
else:
|
else:
|
||||||
pretty_print({"data": device.data})
|
pretty_print({"data": device.data})
|
||||||
|
@ -129,7 +129,7 @@ class HonConnection:
|
|||||||
},
|
},
|
||||||
"ancillaryParameters": ancillary_parameters,
|
"ancillaryParameters": ancillary_parameters,
|
||||||
"parameters": parameters,
|
"parameters": parameters,
|
||||||
"applianceType": device.appliance_type_name
|
"applianceType": device.appliance_type
|
||||||
}
|
}
|
||||||
url = f"{const.API_URL}/commands/v1/send"
|
url = f"{const.API_URL}/commands/v1/send"
|
||||||
async with self._session.post(url, headers=await self._headers, json=data) as resp:
|
async with self._session.post(url, headers=await self._headers, json=data) as resp:
|
||||||
|
0
pyhon/appliances/__init__.py
Normal file
0
pyhon/appliances/__init__.py
Normal file
@ -5,4 +5,6 @@ class Appliance:
|
|||||||
def get(self):
|
def get(self):
|
||||||
if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
self._data["attributes"]["parameters"]["machMode"] = "0"
|
self._data["attributes"]["parameters"]["machMode"] = "0"
|
||||||
|
self._data["active"] = bool(self._data.get("activity"))
|
||||||
|
self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3"
|
||||||
return self._data
|
return self._data
|
||||||
|
@ -38,7 +38,7 @@ class HonCommand:
|
|||||||
return {key: parameter.value for key, parameter in self._ancillary_parameters.items()}
|
return {key: parameter.value for key, parameter in self._ancillary_parameters.items()}
|
||||||
|
|
||||||
async def send(self):
|
async def send(self):
|
||||||
parameters = {name: parameter.value for name, parameter in self._parameters}
|
parameters = {name: parameter.value for name, parameter in self._parameters.items()}
|
||||||
return await self._connector.send_command(self._device, self._name, parameters, self.ancillary_parameters)
|
return await self._connector.send_command(self._device, self._name, parameters, self.ancillary_parameters)
|
||||||
|
|
||||||
def get_programs(self):
|
def get_programs(self):
|
||||||
|
@ -23,7 +23,7 @@ class HonDevice:
|
|||||||
if "." in item:
|
if "." in item:
|
||||||
result = self.data
|
result = self.data
|
||||||
for key in item.split("."):
|
for key in item.split("."):
|
||||||
if all([k in "0123456789" for k in key]):
|
if all([k in "0123456789" for k in key]) and type(result) is list:
|
||||||
result = result[int(key)]
|
result = result[int(key)]
|
||||||
else:
|
else:
|
||||||
result = result[key]
|
result = result[key]
|
||||||
@ -31,7 +31,15 @@ class HonDevice:
|
|||||||
else:
|
else:
|
||||||
if item in self.data:
|
if item in self.data:
|
||||||
return self.data[item]
|
return self.data[item]
|
||||||
return self.attributes["parameters"].get(item, self.appliance[item])
|
if item in self.attributes["parameters"]:
|
||||||
|
return self.attributes["parameters"].get(item)
|
||||||
|
return self.appliance[item]
|
||||||
|
|
||||||
|
def get(self, item, default=None):
|
||||||
|
try:
|
||||||
|
return self[item]
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
return default
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def appliance_model_id(self):
|
def appliance_model_id(self):
|
||||||
@ -120,7 +128,7 @@ class HonDevice:
|
|||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
result = {"attributes": self.attributes, "appliance": self.appliance, "statistics": self.statistics,
|
result = {"attributes": self.attributes, "appliance": self.appliance, "statistics": self.statistics,
|
||||||
"commands": self.parameters}
|
**self.parameters}
|
||||||
if self._extra:
|
if self._extra:
|
||||||
return result | self._extra.Appliance(result).get()
|
return result | self._extra.Appliance(result).get()
|
||||||
return result
|
return result
|
||||||
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.3.0",
|
version="0.3.3",
|
||||||
author="Andre Basche",
|
author="Andre Basche",
|
||||||
description="Control hOn devices with python",
|
description="Control hOn devices with python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
Reference in New Issue
Block a user