コード例 #1
0
ファイル: agent.py プロジェクト: OpenBMS/volttron-demo
    def on_match_all(self, peer, sender, bus, topic, headers, message):
        agent_id = headers.get(headers_mod.FROM)
        if agent_id is None or agent_id == AGENT_ID:
            return

        device_type = "/".join(topic.split("/")[0:2])
        if not self.agents_context_map.has_key(agent_id):
            self.agents_context_map[agent_id] = {}

        cur_agent_context = self.agents_context_map[agent_id]
        # TODO: We can think of adding the type only when the context is newly created
        cur_agent_context["device_type"] = device_type
        cur_agent_context.update({"location": headers.get("Location")})
        # extract specific property (such as voltage, power etc.) from the topic
        cur_agent_context.update({topic.split("/")[-1]: jsonapi.loads(message)})
        self.agents_context_map[agent_id].update(cur_agent_context)
        HouseHTTPServer.set_buffer(self.dashboard_data())

        if self.total_power() != self.previous_power:
            self.previous_power = self.total_power()
            self.publish_total_power_to_cloud()
コード例 #2
0
ファイル: agent.py プロジェクト: OpenBMS/volttron-demo
    def __init__(self, config_path, **kwargs):
        super(HouseCoordinator, self).__init__(**kwargs)

        config = utils.load_config(config_path)
        self.power_price_thresholds = {
            "low": float(config.get("low_price_threshold")),
            "high": float(config.get("high_price_threshold")),
        }

        # dict which maintains state of agents connected to Home coordinator
        self.agents_context_map = {}
        # current mode (economy or comfort)
        self.mode = config.get("default_profile")
        # current power price (in cents per kWh)
        self.power_price = DEFAULT_POWER_PRICE
        self.previous_power = 0
        self.disruption = False
        # Initialize Energy profile map, which indicates highest allowed operating
        # states for each of the device, given a mode and price level
        self.init_energy_profile_map()
        HouseHTTPServer.set_instance(self)
        t = threading.Thread(target=start_server)
        t.start()