Skip to content

Commit

Permalink
fix friendly_name key error
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmotea committed Aug 22, 2022
1 parent 498bfac commit 0a631cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions BridgeEmulator/HueObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ def update_attr(self, newdata):

streamMessage = {"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Room() if self.type == "Room" else self.getV2Zone()],
"owner":{
"rid":self.getV2Room()["id"] if self.type == "Room" else self.getV2Zone()["id"],
"rtype": "room" if self.type == "Room" else "zone"
},
"id": str(uuid.uuid4()),
"type": "update"
}
Expand Down Expand Up @@ -1062,12 +1066,17 @@ def genStreamEvent(self, v2State):
streamMessage["data"][0].update(v2State)
eventstream.append(streamMessage)
streamMessage = {"creationtime": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "grouped_light"}],
"data": [{"id": self.id_v2, "type": "grouped_light",
"owner":{
"rid":self.getV2Room()["id"] if self.type == "Room" else self.getV2Zone()["id"],
"rtype": "room" if self.type == "Room" else "zone"
}
}],
"id": str(uuid.uuid4()),
"type": "update"
}
streamMessage["id_v1"] = "/groups/" + self.id_v1
streamMessage.update(v2State)
streamMessage["data"][0].update(v2State)
eventstream.append(streamMessage)

def getV1Api(self):
Expand Down
4 changes: 2 additions & 2 deletions BridgeEmulator/services/homeAssistantWS.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _send(self, payload):
def connect_if_required():
if homeassistant_ws_client is None or homeassistant_ws_client.client_terminated:
create_websocket_client()

return homeassistant_ws_client


Expand Down Expand Up @@ -274,7 +274,7 @@ def discover(detectedLights):
for entity_id in latest_states.keys():
ha_state = latest_states[entity_id]
device_new = True
lightName = ha_state["attributes"]["friendly_name"] if ha_state["attributes"]["friendly_name"] is not None else entity_id
lightName = ha_state["attributes"]["friendly_name"] if "friendly_name" in ha_state["attributes"] else entity_id

logging.info("HomeAssistant_ws: found light {}".format(lightName))
# From Home Assistant lights/__init.py__
Expand Down

0 comments on commit 0a631cc

Please sign in to comment.