12345678910111213141516171819202122232425262728 |
- def shift_response(d):
- def shift_dict(d_):
- d_k = list(map(int, d_.keys()))
- if not len(d_k):
- return d_
-
- d_k.sort()
- offset = d_k[0]-1
-
- d_res = {
- str(k - offset): d_[k]
- for k in d_k
- if (k in d_)
- }
-
- return d_res
-
- d_shifted = { 'macAddress': d['macAddress'] }
- if 'Analog' in d.keys():
- d_shifted['Analog'] = shift_dict(d['Analog'])
-
- if 'Integer' in d.keys():
- d_shifted['Integer'] = shift_dict(d['Integer'])
-
- if 'Digital' in d.keys():
- d_shifted['Digital'] = shift_dict(d['Digital'])
-
- return d_shifted
|