I am working on my first plugin, and I have hit the end of my knowledge. I get the following json back, by doing
- Code: Select all
status=requests.get(url)
alljson = json.loads(status.text)
- Code: Select all
{u'info': {u'opt': 119, u'core': u'2_5_2', u'leds': {u'count': 151, u'rgbw': False, u'maxpwr': 850, u'pwr': 847, u'pin': [2], u'maxseg': 10}, u'udpport': 21324, u'ver': u'0.8.6', u'name': u'WLED', u'vid': 1910255, u'brand': u'WLED', u'palcount': 50, u'uptime': 164461, u'product': u'DIY light', u'live': False, u'btype': u'bin', u'fxcount': 83, u'freeheap': 20480, u'mac': u'2cf432779560', u'arch': u'esp8266'}, u'state': {u'on': True, u'nl': {u'on': False, u'dur': 60, u'tbri': 0, u'fade': True}, u'ps': -1, u'udpn': {u'recv': True, u'send': False}, u'transition': 650, u'seg': [{u'ix': 128, u'cln': -1, u'sx': 170, u'fx': 54, u'rev': False, u'stop': 151, u'len': 151, u'col': [[11, 22, 33], [0, 51, 255], [0, 0, 0]], u'start': 0, u'sel': True, u'pal': 8, u'id': 0}], u'bri': 255, u'pl': -1}, u'palettes': [u'Default', u'Random Cycle', u'Primary Color', u'Based on Primary', u'Set Colors', u'Based on Set', u'Party', u'Cloud', u'Lava', u'Ocean', u'Forest', u'Rainbow', u'Rainbow Bands', u'Sunset', u'Rivendell', u'Breeze', u'Red & Blue', u'Yellowout', u'Analogous', u'Splash', u'Pastel', u'Sunset 2', u'Beech', u'Vintage', u'Departure', u'Landscape', u'Beach', u'Sherbet', u'Hult', u'Hult 64', u'Drywet', u'Jul', u'Grintage', u'Rewhi', u'Tertiary', u'Fire', u'Icefire', u'Cyane', u'Light Pink', u'Autumn', u'Magenta', u'Magred', u'Yelmag', u'Yelblu', u'Orange & Teal', u'Tiamat', u'April Night', u'Orangery', u'C9', u'Sakura'], u'effects': [u'Solid', u'Blink', u'Breathe', u'Wipe', u'Wipe Random', u'Random Colors', u'Sweep', u'Dynamic', u'Colorloop', u'Rainbow', u'Scan', u'Dual Scan', u'Fade', u'Chase', u'Chase Rainbow', u'Running', u'Saw', u'Twinkle', u'Dissolve', u'Dissolve Rnd', u'Sparkle', u'Dark Sparkle', u'Sparkle+', u'Strobe', u'Strobe Rainbow', u'Mega Strobe', u'Blink Rainbow', u'Android', u'Chase', u'Chase Random', u'Chase Rainbow', u'Chase Flash', u'Chase Flash Rnd', u'Rainbow Runner', u'Colorful', u'Traffic Light', u'Sweep Random', u'Running 2', u'Red & Blue', u'Stream', u'Scanner', u'Lighthouse', u'Fireworks', u'Rain', u'Merry Christmas', u'Fire Flicker', u'Gradient', u'Loading', u'In Out', u'In In', u'Out Out', u'Out In', u'Circus', u'Halloween', u'Tri Chase', u'Tri Wipe', u'Tri Fade', u'Lightning', u'ICU', u'Multi Comet', u'Dual Scanner', u'Stream 2', u'Oscillate', u'Pride 2015', u'Juggle', u'Palette', u'Fire 2012', u'Colorwaves', u'BPM', u'Fill Noise', u'Noise 1', u'Noise 2', u'Noise 3', u'Noise 4', u'Colortwinkles', u'Lake', u'Meteor', u'Smooth Meteor', u'Railway', u'Ripple', u'Twinklefox', u'Twinklecat', u'Halloween Eyes']}
I then can extract just the status by
- Code: Select all
statusjson = alljson.get("state")
Which returns
- Code: Select all
{u'on': True, u'nl': {u'on': False, u'dur': 60, u'tbri': 0, u'fade': True}, u'ps': -1, u'udpn': {u'recv': True, u'send': False}, u'transition': 650, u'seg': [{u'ix': 128, u'cln': -1, u'sx': 170, u'fx': 54, u'rev': False, u'stop': 151, u'len': 151, u'col': [[11, 22, 33], [0, 51, 255], [0, 0, 0]], u'start': 0, u'sel': True, u'pal': 8, u'id': 0}], u'bri': 255, u'pl': -1}
I have had no problem extracting the states I need with statusjson["transition"] for example. I am struggling to then get the elements I need from the "seg" portion as when I try to get just that with
- Code: Select all
segjson = statusjson.get("seg")
I get the following
- Code: Select all
[{u'ix': 128, u'cln': -1, u'sx': 170, u'fx': 54, u'rev': False, u'stop': 151, u'len': 151, u'col': [[11, 22, 33], [0, 51, 255], [0, 0, 0]], u'start': 0, u'sel': True, u'pal': 8, u'id': 0}]
Which I can no longer extract individual elements, and I am out of my depth. I am especially interested in the "col" values, but also the "pal" but I don't seem to be able to reference those elements at all.
Any pointers ?