async def async_update_light(self, request: web.Request, request_data: dict): """Handle requests to update a light.""" light_id = request.match_info["light_id"] username = request.match_info["username"] light_conf = await self.config.async_get_storage_value( "lights", light_id) if not light_conf: return send_error_response(request.path, "no light config", 404) update_dict(light_conf, request_data) return send_success_response(request.path, request_data, username)
async def async_update_light(self, request: web.Request, request_data: dict): """Handle requests to update a light.""" light_id = request.match_info["light_id"] username = request.match_info["username"] light_conf = await self.config.async_get_storage_value( "lights", light_id) if not light_conf: return web.Response(status=404) update_dict(light_conf, request_data) response = await self.__async_create_hue_response( request.path, request_data, username) return send_json_response(response)
async def async_update_localitem(self, request: web.Request, request_data: dict): """Handle requests to update an item in localstorage.""" item_id = request.match_info["item_id"] itemtype = request.match_info["itemtype"] username = request.match_info["username"] local_item = await self.config.async_get_storage_value( itemtype, item_id) if not local_item: return send_error_response(request.path, "no localitem", 404) update_dict(local_item, request_data) await self.config.async_set_storage_value(itemtype, item_id, local_item) return send_success_response(request.path, request_data, username)
async def async_update_localitem(self, request: web.Request, request_data: dict): """Handle requests to update an item in localstorage.""" item_id = request.match_info["item_id"] itemtype = request.match_info["itemtype"] username = request.match_info["username"] local_item = await self.config.async_get_storage_value( itemtype, item_id) if not local_item: return web.Response(status=404) update_dict(local_item, request_data) await self.config.async_set_storage_value(itemtype, item_id, local_item) response = await self.__async_create_hue_response( request.path, request_data, username) return web.json_response(response)
async def async_update_group(self, request: web.Request, request_data: dict): """Handle requests to update a group.""" group_id = request.match_info["group_id"] username = request.match_info["username"] local_group = await self.config.async_get_storage_value( "groups", group_id) if not local_group: return web.Response(status=404) update_dict(local_group, request_data) # Hue entertainment support (experimental) if "stream" in local_group: if local_group["stream"].get("active"): # Requested streaming start LOGGER.debug( "Start Entertainment mode for group %s - params: %s", group_id, request_data, ) if not self.streaming_api: user_data = await self.config.async_get_user(username) self.streaming_api = EntertainmentAPI( self.hue, local_group, user_data) local_group["stream"]["owner"] = username if not local_group["stream"].get("proxymode"): local_group["stream"]["proxymode"] = "auto" if not local_group["stream"].get("proxynode"): local_group["stream"]["proxynode"] = "/bridge" else: # Request streaming stop LOGGER.info( "Stop Entertainment mode for group %s - params: %s", group_id, request_data, ) local_group["stream"] = {"active": False} if self.streaming_api: # stop service if needed self.streaming_api.stop() self.streaming_api = None await self.config.async_set_storage_value("groups", group_id, local_group) response = await self.__async_create_hue_response( request.path, request_data, username) return web.json_response(response)
async def async_update_group(self, request: web.Request, request_data: dict): """Handle requests to update a group.""" group_id = request.match_info["group_id"] username = request.match_info["username"] group_conf = await self.config.async_get_storage_value( "groups", group_id) if not group_conf: return send_error_response(request.path, "no group config", 404) update_dict(group_conf, request_data) # Hue entertainment support (experimental) if "stream" in group_conf: if group_conf["stream"].get("active"): # Requested streaming start LOGGER.debug( "Start Entertainment mode for group %s - params: %s", group_id, request_data, ) del group_conf["stream"]["active"] if not self.streaming_api: user_data = await self.config.async_get_user(username) self.streaming_api = EntertainmentAPI( self.hue, group_conf, user_data) group_conf["stream"]["owner"] = username if not group_conf["stream"].get("proxymode"): group_conf["stream"]["proxymode"] = "auto" if not group_conf["stream"].get("proxynode"): group_conf["stream"]["proxynode"] = "/bridge" else: # Request streaming stop LOGGER.info( "Stop Entertainment mode for group %s - params: %s", group_id, request_data, ) if self.streaming_api: # stop service if needed self.streaming_api.stop() self.streaming_api = None await self.config.async_set_storage_value("groups", group_id, group_conf) return send_success_response(request.path, request_data, username)