Skip to content

Commit cf02c52

Browse files
committed
Merge branch 'master' of github.com:diyhue/diyHue
2 parents 106e5ea + 20e718d commit cf02c52

File tree

7 files changed

+90
-31
lines changed

7 files changed

+90
-31
lines changed

BridgeEmulator/HueEmulator3.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def runHttp(BIND_IP, HOST_HTTP_PORT):
109109
HOST_HTTP_PORT = configManager.runtimeConfig.arg["HTTP_PORT"]
110110
HOST_HTTPS_PORT = configManager.runtimeConfig.arg["HTTPS_PORT"]
111111
CONFIG_PATH = configManager.runtimeConfig.arg["CONFIG_PATH"]
112+
DISABLE_HTTPS = configManager.runtimeConfig.arg["noServeHttps"]
112113

113114
Thread(target=daylightSensor, args=[bridgeConfig["config"]["timezone"], bridgeConfig["sensors"]["1"]]).start()
114115
### start services
@@ -127,5 +128,6 @@ def runHttp(BIND_IP, HOST_HTTP_PORT):
127128
Thread(target=mdns.mdnsListener, args=[HOST_IP, HOST_HTTP_PORT, "BSB002", bridgeConfig["config"]["bridgeid"]]).start()
128129
Thread(target=scheduler.runScheduler).start()
129130
Thread(target=eventStreamer.messageBroker).start()
130-
Thread(target=runHttps, args=[BIND_IP, HOST_HTTPS_PORT, CONFIG_PATH]).start()
131+
if not DISABLE_HTTPS:
132+
Thread(target=runHttps, args=[BIND_IP, HOST_HTTPS_PORT, CONFIG_PATH]).start()
131133
runHttp(BIND_IP, HOST_HTTP_PORT)

BridgeEmulator/configManager/argumentHandler.py

+3
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,7 @@ def parse_arguments():
174174
logging.info("Online Discovery/Remote API Enabled!")
175175
argumentDict["disableOnlineDiscover"] = disableOnlineDiscover
176176

177+
if argumentDict['noServeHttps']:
178+
logging.info("HTTPS Port Disabled")
179+
177180
return argumentDict

BridgeEmulator/configManager/configHandler.py

+46-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,57 @@ def load_config(self):
5252
# updgrade config
5353
if "homeassistant" not in config:
5454
config["homeassistant"] = {"enabled": False}
55-
56-
if int(config["swversion"]) < 1950207110:
57-
config["swversion"] = "1950207110"
55+
if "yeelight" not in config:
56+
config["yeelight"] = {"enabled": True}
57+
if "native_multi" not in config:
58+
config["native_multi"] = {"enabled": True}
59+
if "tasmota" not in config:
60+
config["tasmota"] = {"enabled": True}
61+
if "wled" not in config:
62+
config["wled"] = {"enabled": True}
63+
if "shelly" not in config:
64+
config["shelly"] = {"enabled": True}
65+
if "esphome" not in config:
66+
config["esphome"] = {"enabled": True}
67+
if "hyperion" not in config:
68+
config["hyperion"] = {"enabled": True}
69+
if "tpkasa" not in config:
70+
config["tpkasa"] = {"enabled": True}
71+
72+
if int(config["swversion"]) < 1952086020:
73+
config["swversion"] = "1952086020"
5874
if float(config["apiversion"][:3]) < 1.50:
5975
config["apiversion"] = "1.50.0"
6076

6177
self.yaml_config["config"] = config
6278
else:
63-
self.yaml_config["config"] = {"Remote API enabled": False, "Hue Essentials key": str(uuid.uuid1()).replace('-', ''), "discovery": True, "mqtt":{"enabled":False},"deconz":{"enabled":False},"alarm":{"enabled": False, "lasttriggered": 0},"apiUsers":{},"apiversion":"1.46.0","name":"DiyHue Bridge","netmask":"255.255.255.0","swversion":"1946157000","timezone":"Europe/London","linkbutton":{"lastlinkbuttonpushed": 1599398980},"users":{"[email protected]":{"password":"pbkdf2:sha256:150000$bqqXSOkI$199acdaf81c18f6ff2f29296872356f4eb78827784ce4b3f3b6262589c788742"}}, "hue": {}, "tradfri": {}, "tradfri": {}, "homeassistant": {"enabled":False}}
79+
self.yaml_config["config"] = {
80+
"Remote API enabled": False,
81+
"Hue Essentials key": str(uuid.uuid1()).replace('-', ''),
82+
"discovery": True,
83+
"mqtt":{"enabled":False},
84+
"deconz":{"enabled":False},
85+
"alarm":{"enabled": False,"lasttriggered": 0},
86+
"apiUsers":{},
87+
"apiversion":"1.46.0",
88+
"name":"DiyHue Bridge",
89+
"netmask":"255.255.255.0",
90+
"swversion":"1946157000",
91+
"timezone":"Europe/London",
92+
"linkbutton":{"lastlinkbuttonpushed": 1599398980},
93+
"users":{"[email protected]":{"password":"pbkdf2:sha256:150000$bqqXSOkI$199acdaf81c18f6ff2f29296872356f4eb78827784ce4b3f3b6262589c788742"}},
94+
"hue": {},
95+
"tradfri": {},
96+
"homeassistant": {"enabled":False},
97+
"yeelight": {"enabled":True},
98+
"native_multi": {"enabled":True},
99+
"tasmota": {"enabled":True},
100+
"wled": {"enabled":True},
101+
"shelly": {"enabled":True},
102+
"esphome": {"enabled":True},
103+
"hyperion": {"enabled":True},
104+
"tpkasa": {"enabled":True},
105+
}
64106
# load lights
65107
if os.path.exists(self.configDir + "/lights.yaml"):
66108
lights = _open_yaml(self.configDir + "/lights.yaml")

BridgeEmulator/lights/discover.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,27 @@ def scanForLights(): # scan for ESP8266 lights and strips
114114
deconz.discover(detectedLights, bridgeConfig["config"]["deconz"])
115115
if bridgeConfig["config"]["homeassistant"]["enabled"]:
116116
discover(detectedLights)
117-
yeelight.discover(detectedLights)
117+
if bridgeConfig["config"]["yeelight"]["enabled"]:
118+
yeelight.discover(detectedLights)
118119
# native_multi probe all esp8266 lights with firmware from diyhue repo
119-
native_multi.discover(detectedLights, device_ips)
120-
tasmota.discover(detectedLights, device_ips)
121-
wled.discover(detectedLights, device_ips)
120+
if bridgeConfig["config"]["native_multi"]["enabled"]:
121+
native_multi.discover(detectedLights, device_ips)
122+
if bridgeConfig["config"]["tasmota"]["enabled"]:
123+
tasmota.discover(detectedLights, device_ips)
124+
if bridgeConfig["config"]["wled"]["enabled"]:
125+
# Most of the other discoveries are disabled by having no IP address (--disable-network-scan)
126+
# But wled does an mdns discovery as well.
127+
wled.discover(detectedLights, device_ips)
122128
hue.discover(detectedLights, bridgeConfig["config"]["hue"])
123-
shelly.discover(detectedLights, device_ips)
124-
esphome.discover(detectedLights, device_ips)
129+
if bridgeConfig["config"]["shelly"]["enabled"]:
130+
shelly.discover(detectedLights, device_ips)
131+
if bridgeConfig["config"]["esphome"]["enabled"]:
132+
esphome.discover(detectedLights, device_ips)
125133
tradfri.discover(detectedLights, bridgeConfig["config"]["tradfri"])
126-
hyperion.discover(detectedLights)
127-
tpkasa.discover(detectedLights)
134+
if bridgeConfig["config"]["hyperion"]["enabled"]:
135+
hyperion.discover(detectedLights)
136+
if bridgeConfig["config"]["tpkasa"]["enabled"]:
137+
tpkasa.discover(detectedLights)
128138
bridgeConfig["temp"]["scanResult"]["lastscan"] = datetime.now().strftime(
129139
"%Y-%m-%dT%H:%M:%S")
130140
for light in detectedLights:

BridgeEmulator/lights/protocols/homeassistant_ws.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ def get_light_state(light):
8282
entity_id = light.protocol_cfg["entity_id"]
8383
homeassistant_state = latest_states[entity_id]
8484
existing_diy_hue_state = light.state
85-
pprint(translate_homeassistant_state_to_diyhue_state(existing_diy_hue_state, homeassistant_state))
85+
# pprint(translate_homeassistant_state_to_diyhue_state(existing_diy_hue_state, homeassistant_state))
8686
return translate_homeassistant_state_to_diyhue_state(existing_diy_hue_state, homeassistant_state)

BridgeEmulator/services/entertainment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def entertainmentService(group, user):
267267
color = wledLights[ip]["color"] * int(wledLights[ip]["ledCount"])
268268
udpdata = bytes(udphead+color)
269269
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
270-
sock.sendto(udpdata, (ip, 21324))
270+
sock.sendto(udpdata, (ip.split(":")[0], 21324))
271271
if len(hueGroupLights) != 0:
272272
h.send(hueGroupLights, hueGroup)
273273
else:

BridgeEmulator/services/homeAssistantWS.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ def change_light(self, light, data):
116116
"service_data": service_data
117117
}
118118

119-
payload["service"] = "turn_off"
119+
payload["service"] = "turn_on"
120120
if 'on' in data:
121-
if data['on']:
122-
payload["service"] = "turn_on"
121+
if not data['on']:
122+
payload["service"] = "turn_off"
123123

124124
color_from_hsv = False
125125
for key, value in data.items():
@@ -212,9 +212,7 @@ def _send(self, payload):
212212

213213

214214
def connect_if_required():
215-
print("A")
216215
if homeassistant_ws_client is None or homeassistant_ws_client.client_terminated:
217-
print("B")
218216
create_websocket_client()
219217

220218
return homeassistant_ws_client
@@ -280,21 +278,25 @@ def discover(detectedLights):
280278

281279
logging.info("HomeAssistant_ws: found light {}".format(lightName))
282280
# From Home Assistant lights/__init.py__
283-
SUPPORT_BRIGHTNESS = 1
284-
SUPPORT_COLOR_TEMP = 2
285-
SUPPORT_EFFECT = 4
286-
SUPPORT_FLASH = 8
287-
SUPPORT_COLOR = 16
288-
SUPPORT_TRANSITION = 32
289-
SUPPORT_WHITE_VALUE = 128
290-
supported_features = ha_state['attributes']['supported_features']
281+
UNKNOWN = "unknown" # Ambiguous color mode
282+
ONOFF = "onoff" # Must be the only supported mode
283+
BRIGHTNESS = "brightness" # Must be the only supported mode
284+
COLOR_TEMP = "color_temp"
285+
HS = "hs"
286+
XY = "xy"
287+
RGB = "rgb"
288+
RGBW = "rgbw"
289+
RGBWW = "rgbww"
290+
WHITE = "white" # Must *NOT* be the only supported mode
291+
292+
supported_colourmodes = ha_state.get('attributes', {}).get('supported_color_modes', [])
291293

292294
model_id = None
293-
if supported_features & SUPPORT_COLOR:
295+
if HS in supported_colourmodes or XY in supported_colourmodes or RGB in supported_colourmodes or RGBW in supported_colourmodes or RGBWW in supported_colourmodes:
294296
model_id = "LCT015"
295-
elif supported_features & SUPPORT_COLOR_TEMP:
297+
elif COLOR_TEMP in supported_colourmodes:
296298
model_id = "LTW001"
297-
elif supported_features & SUPPORT_BRIGHTNESS:
299+
elif BRIGHTNESS in supported_colourmodes:
298300
model_id = "LWB010"
299301
else:
300302
model_id = "LOM001"

0 commit comments

Comments
 (0)