class EnergySystem(): def __init__(self): self.components = [] def add_components(self, *args): for comp in args: self.components.append(comp) def get_state_and_store_to_database(self, db): state = {} for comp in self.components: component_state = comp.get_state() state[comp.device_name] = component_state db.store_data(comp.device_name, component_state) return state def get_component_by_name(self, name): for comp in self.components: if comp.device_name == name: return comp