mijiaAPI 1.3.1__tar.gz → 1.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mijiaAPI
3
- Version: 1.3.1
3
+ Version: 1.3.2
4
4
  Summary: A Python API for Xiaomi Mijia
5
5
  Home-page: https://github.com/Do1e/mijia-api
6
6
  License: GPLv3
@@ -16,11 +16,13 @@ class DevProp(object):
16
16
  self.rw = prop_dict['rw']
17
17
  self.unit = prop_dict['unit']
18
18
  self.range = prop_dict['range']
19
+ self.value_list = prop_dict.get('value-list', None)
19
20
  self.method = prop_dict['method']
20
21
 
21
22
  def __str__(self):
22
23
  return f' {self.name}: {self.desc}\n' \
23
- f' valuetype: {self.type}, rw: {self.rw}, unit: {self.unit}, range: {self.range}'
24
+ f' valuetype: {self.type}, rw: {self.rw}, unit: {self.unit}, range: {self.range}' + \
25
+ (('\n ' + ', '.join([f'{item["value"]}: {item["description"]}' for item in self.value_list])) if self.value_list else '')
24
26
 
25
27
  class DevAction(object):
26
28
  def __init__(self, act_dict: dict):
@@ -60,6 +62,9 @@ class mijiaDevices(object):
60
62
  prop = self.prop_list[name]
61
63
  if 'w' not in prop.rw:
62
64
  raise ValueError(f'Property {name} is read-only')
65
+ if prop.value_list:
66
+ if value not in [item['value'] for item in prop.value_list]:
67
+ raise ValueError(f'Invalid value: {value}, should be in {prop.value_list}')
63
68
  if prop.type == 'bool':
64
69
  if not isinstance(value, bool):
65
70
  raise ValueError(f'Invalid value for bool: {value}, should be True or False')
@@ -181,6 +186,7 @@ def get_device_info(device_model: str) -> dict:
181
186
  ]),
182
187
  'unit': prop.get('unit', None),
183
188
  'range': prop.get('value-range', None),
189
+ 'value-list': prop.get('value-list', None),
184
190
  'method': {
185
191
  'siid': int(siid),
186
192
  'piid': int(piid)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mijiaAPI"
3
- version = "1.3.1"
3
+ version = "1.3.2"
4
4
  description = "A Python API for Xiaomi Mijia"
5
5
  authors = ["Do1e <dpj.email@qq.com>"]
6
6
  license = "GPLv3"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes