setup_devices.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:senic-hub 作者: getsenic 项目源码 文件源码
def devices_details_view(request):
    device_id = request.matchdict["device_id"]
    logger.debug("Getting details for device with ID=%s", device_id)

    device_list_path = request.registry.settings['devices_path']
    device = get_device(device_list_path, device_id)

    # Only Philips Hue has device details at the moment
    # TODO: In the future, each single Philips Hue light should be returned as a regular
    #       device. Philips Hue bridges should be flagged with `virtual: True` since they
    #       are not controlled by the user. However, all its lights should be returned as
    #       well when requesting `/devices`.
    if device['type'] != 'philips_hue':
        return {}

    homeassistant_data_path = request.registry.settings["homeassistant_data_path"]
    phue_bridge_config = os.path.join(homeassistant_data_path, '{}.conf'.format(device["id"]))
    config = read_json(phue_bridge_config, {})
    username = config.get(device["ip"], {}).get("username")

    try:
        bridge = PhilipsHueBridgeApiClient(device["ip"], username)

        return bridge.get_lights()
    # TODO create a tween to handle exceptions for all views
    except UnauthenticatedDeviceError as e:
        raise HTTPBadRequest(e.message)
    except UpstreamError as e:
        raise HTTPBadGateway(e.message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号