devnicolasc / SonoffBasic

MIT License
4 stars 2 forks source link

KeyError: 'switch' #3

Open Doncode opened 2 years ago

Doncode commented 2 years ago
SonoffBasic/sonoff.py", line 59, in devices
    'status': i['params']['switch'],
KeyError: 'switch'
devnicolasc commented 2 years ago

Hi, can you add more details please? which device model? or if it possible can you print the response in json type from line 50: r = requests.get(self.baseurl + 'api/user/device', params=payload, headers={'Authorization': self.auth}) ?

Doncode commented 2 years ago
{'__v': 0,
 '_id': '61ffa29ba27d6c000******',
 'apikey': 'eca6f6f3-d1a2-405a-bcf4-******',
 'brandLogoUrl': '',
 'brandName': 'coolkit',
 'createdAt': '2022-02-06T10:27:39.641Z',
 'devConfig': {},
 'devGroups': [],
 'deviceUrl': '',
 'deviceid': '10014c4******',
 'devicekey': 'bae6234e-1897-******',
 'extra': {'_id': '6145ac8b4dd******',
           'extra': {'apmac': 'd0:27:02:******',
                     'brandId': '59e0dbc25c1af******',
                     'chipid': '7CB94C******',
                     'description': '2021-09-18 蒲玖云 WW210771',
                     'mac': 'd0:27:02******',
                     'manufacturer': '深圳酷宅科技有限公司',
                     'model': 'CK-BL602-4SW-HS',
                     'modelInfo': '60d53d358d34******',
                     'ui': '单通道插座_支持2.4G轻智能',
                     'uiid': 130}},
 'family': {'id': '61eb0fa12d1a******', 'index': 0, 'members': []},
 'group': '',
 'groups': [],
 'ip': '31.******',
 'location': '',
 'name': 'Device******',
 'offlineTime': '2022-02-08T14:02:03.376Z',
 'online': False,
 'onlineTime': '2022-02-08T14:00:00.881Z',
 'params': {'addr': 'e1fb6******',
            'bindInfos': {'alice': []},
            'bssid': '20:15:******',
            'configure': [{'outlet': 0, 'startup': 'off'},
                          {'outlet': 1, 'startup': 'off'},
                          {'outlet': 2, 'startup': 'off'},
                          {'outlet': 3, 'startup': 'off'}],
            'fwVersion': '1.2.2',
            'lightScenes_0': [],
            'lightScenes_1': [],
            'lightScenes_2': [],
            'lightScenes_3': [],
            'pulses': [{'outlet': 0,
                        'pulse': 'on',
                        'switch': 'off',
                        'width': 3000},
                       {'outlet': 1,
                        'pulse': 'off',
                        'switch': 'on',
                        'width': 0},
                       {'outlet': 2,
                        'pulse': 'off',
                        'switch': 'on',
                        'width': 0},
                       {'outlet': 3,
                        'pulse': 'off',
                        'switch': 'on',
                        'width': 0}],
            'remoteCtrlList': [{'addr': [], 'outlet': 0},
                               {'addr': [], 'outlet': 1},
                               {'addr': [], 'outlet': 2},
                               {'addr': [], 'outlet': 3}],
            'rssi': -42,
            'sledOnline': 'on',
            'ssid': 'nonet******',
            'switches': [{'outlet': 0, 'switch': 'off'},
                         {'outlet': 1, 'switch': 'off'},
                         {'outlet': 2, 'switch': 'off'},
                         {'outlet': 3, 'switch': 'off'}],
            'version': 8},
 'productModel': 'CK-BL602-******',
 'relational': [],
 'settings': {'alarmNotify': 1,
              'appDoorbellNotify': 1,
              'opsHistory': 1,
              'opsNotify': 0,
              'wxAlarmNotify': 0,
              'wxDoorbellNotify': 0,
              'wxOpsNotify': 0},
 'sharedTo': [{'note': '', 'permit': 15, 'phoneNumber': '***@yandex.ru'}],
 'showBrand': False,
 'tags': {'m_******': 'on', 'm_******': 'off'},
 'type': '10',
 'uiid': 138}
Doncode commented 2 years ago

https://github.com/Doncode/sonoff-python this working in my case