Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite already known lamp types. #1005

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions BridgeEmulator/HueObjects/BehaviorInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ def __init__(self, data):
self.active = data["active"] if "active" in data else False
self.script_id = data["script_id"] if "script_id" in data else ""

streamMessage = {"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "add"
}
streamMessage = {
"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "add"
}
StreamEvent(streamMessage)

def __del__(self):
streamMessage = {"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "behavior_instance"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
streamMessage = {
"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "behavior_instance"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
StreamEvent(streamMessage)
logging.info(self.name + " behaviour instance was destroyed.")

Expand Down Expand Up @@ -70,16 +72,19 @@ def update_attr(self, newdata):
setattr(self, key, updateAttribute)
else:
setattr(self, key, value)
streamMessage = {"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "update"
}
streamMessage = {
"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "update"
}
StreamEvent(streamMessage)

def save(self):
result = {"id": self.id_v2, "metadata": {"name": self.name}, "configuration": self.configuration, "enabled": self.enabled, "active": self.active,
"script_id": self.script_id}
result = {
"id": self.id_v2, "metadata": {"name": self.name}, "configuration": self.configuration,
"enabled": self.enabled, "active": self.active, "script_id": self.script_id
}
if self.name != None:
result["metadata"] = {"name": self.name}

Expand Down
93 changes: 47 additions & 46 deletions BridgeEmulator/HueObjects/EntertainmentConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,49 @@

class EntertainmentConfiguration():
def __init__(self, data):
self.name = data["name"] if "name" in data else "Group " + \
data["id_v1"]
self.name = data["name"] if "name" in data else "Group " + data["id_v1"]
self.id_v1 = data["id_v1"]
self.id_v2 = data["id_v2"] if "id_v2" in data else genV2Uuid()
self.configuration_type = data["configuration_type"] if "configuration_type" in data else "3dspace"
self.lights = []
self.action = {"on": False, "bri": 100, "hue": 0, "sat": 254, "effect": "none", "xy": [
0.0, 0.0], "ct": 153, "alert": "none", "colormode": "xy"}
self.action = {
"on": False, "bri": 100, "hue": 0, "sat": 254, "effect": "none",
"xy": [0.0, 0.0], "ct": 153, "alert": "none", "colormode": "xy"
}
self.sensors = []
self.type = data["type"] if "type" in data else "Entertainment"
self.configuration_type = data["configuration_type"] if "configuration_type" in data else "screen"
self.locations = weakref.WeakKeyDictionary()
self.stream = {"proxymode": "auto",
"proxynode": "/bridge", "active": False, "owner": None}
self.stream = {"proxymode": "auto", "proxynode": "/bridge", "active": False, "owner": None}
self.state = {"all_on": False, "any_on": False}
self.dxState = {"all_on": None, "any_on": None}

streamMessage = {"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "add"
}
streamMessage = {
"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "add"
}
StreamEvent(streamMessage)

def __del__(self):
# Groupper light
streamMessage = {"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "grouped_light"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
streamMessage = {
"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "grouped_light"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
streamMessage["id_v1"] = "/groups/" + self.id_v1
StreamEvent(streamMessage)

### Entertainment area ###
streamMessage = {"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.getV2Api()["id"], "type": "entertainment_configuration"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
streamMessage = {
"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.getV2Api()["id"], "type": "entertainment_configuration"}],
"id": str(uuid.uuid4()),
"type": "delete"
}
streamMessage["id_v1"] = "/groups/" + self.id_v1
StreamEvent(streamMessage)
logging.info(self.name + " entertainment area was destroyed.")
Expand All @@ -67,11 +71,12 @@ def update_attr(self, newdata):
setattr(self, key, updateAttribute)
else:
setattr(self, key, value)
streamMessage = {"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "update"
}
streamMessage = {
"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [self.getV2Api()],
"id": str(uuid.uuid4()),
"type": "update"
}
StreamEvent(streamMessage)

def update_state(self):
Expand Down Expand Up @@ -132,19 +137,15 @@ def getV1Api(self):
return result

def getV2Api(self):

gradienStripPositions = [{"x": -0.4000000059604645, "y": 0.800000011920929, "z": -0.4000000059604645},
{"x": -0.4000000059604645,
"y": 0.800000011920929, "z": 0.0},
{"x": -0.4000000059604645, "y": 0.800000011920929,
"z": 0.4000000059604645},
{"x": 0.0, "y": 0.800000011920929,
"z": 0.4000000059604645},
{"x": 0.4000000059604645, "y": 0.800000011920929,
"z": 0.4000000059604645},
{"x": 0.4000000059604645,
"y": 0.800000011920929, "z": 0.0},
{"x": 0.4000000059604645, "y": 0.800000011920929, "z": -0.4000000059604645}]
gradienStripPositions = [
{"x": -0.4000000059604645, "y": 0.800000011920929, "z": -0.4000000059604645},
{"x": -0.4000000059604645, "y": 0.800000011920929, "z": 0.0},
{"x": -0.4000000059604645, "y": 0.800000011920929, "z": 0.4000000059604645},
{"x": 0.0, "y": 0.800000011920929, "z": 0.4000000059604645},
{"x": 0.4000000059604645, "y": 0.800000011920929, "z": 0.4000000059604645},
{"x": 0.4000000059604645, "y": 0.800000011920929, "z": 0.0},
{"x": 0.4000000059604645, "y": 0.800000011920929, "z": -0.4000000059604645}
]

result = {
"configuration_type": self.configuration_type,
Expand Down Expand Up @@ -175,8 +176,7 @@ def getV2Api(self):
channel_id = 0
for light in self.lights:
if light():
result["light_services"].append(
{"rtype": "light", "rid": light().id_v2})
result["light_services"].append({"rtype": "light", "rid": light().id_v2})
entertainmentUuid = str(uuid.uuid5(
uuid.NAMESPACE_URL, light().id_v2 + 'entertainment'))
result["locations"]["service_locations"].append({"equalization_factor": 1, "positions": self.locations[light()],
Expand Down Expand Up @@ -235,11 +235,12 @@ def setV1Action(self, state, scene=None):
self.genStreamEvent(v2State)

def genStreamEvent(self, v2State):
streamMessage = {"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "grouped_light"}],
"id": str(uuid.uuid4()),
"type": "update"
}
streamMessage = {
"creationtime": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"data": [{"id": self.id_v2, "type": "grouped_light"}],
"id": str(uuid.uuid4()),
"type": "update"
}
streamMessage["id_v1"] = "/groups/" + self.id_v1
streamMessage.update(v2State)
StreamEvent(streamMessage)
Expand Down
Loading
Loading