def test_recursive_flatten(): """Test the flatten function.""" data = {"parent1": {"child1": "data1", "child2": "data2"}, "parent2": "data3"} flattened = translation.recursive_flatten("prefix.", data) assert flattened == { "prefix.parent1.child1": "data1", "prefix.parent1.child2": "data2", "prefix.parent2": "data3", }
def device_state_attributes(self): """Return the state attributes of the last update.""" from miio.device import DeviceInfo from miio.airqualitymonitor import AirQualityMonitorStatus info = self._airQualityMonitor.info() # type: DeviceInfo status = self._airQualityMonitor.status() # type: AirQualityMonitorStatus attrs = {} if info: attrs.update(info.__dict__.get('data', {})) if status: attrs.update(status.__dict__.get('data', {})) attrs = recursive_flatten("", attrs) return attrs