コード例 #1
0
ファイル: runScript.py プロジェクト: Alex-Evo-2266/SmartHome
async def actiondev(data):
    for item in data:
        if (item["type"] == "device"):
            systemName = item["systemName"]
            device = devicesArrey.get(systemName)
            device = device["device"]
            val = getvalue(item["value"], {
                "device": device,
                "field": item["action"]
            })
            await setValue(device.systemName, item["action"], val)
        elif (item["type"] == "group"):
            systemName = item["systemName"]
            group = Groups.get(systemName)
            val = getvalue(item["value"], {
                "group": group,
                "field": item["action"]
            })
            await setValueGroup(
                DeviceValueSchema(systemName=group.systemName,
                                  type=item["action"],
                                  status=val))
        elif (item["type"] == "script"):
            templates = None
            fullName = item["systemName"] + ".yml"
            with open(os.path.join(SCRIPTS_DIR, fullName)) as f:
                templates = yaml.safe_load(f)
            runscript(templates)
        elif (item["type"] == "delay"):
            time.sleep(int(item.get("value").get("value")))
        else:
            print("oh")
コード例 #2
0
async def get_group(name: str,
                    data: GroupSchema,
                    auth_data: dict = Depends(token_dep)):
    group = Groups.get(name)
    if not group:
        return JSONResponse(status_code=404, content={"message": "not found"})
    group.fields = data.fields
    group.save()
    return "ok"
コード例 #3
0
async def setValueGroup(data: DeviceValueSchema):
    logger.debug(f'setValueGroup input data:{data.dict()}')
    group = Groups.get(data.systemName)
    if not group:
        return FunctionRespons(status=TypeRespons.INVALID,
                               detail=f"group {data.systemName} not found")
    for item in group.devices:
        device = devicesArrey.get(item.name)
        print(device)
        if not device:
            logger.info(f'device {item.name} not found')
            continue
        field = device["device"].get_field(data.type)
        if not field:
            continue
        if field.type == "number" and not is_digit(data.status):
            continue
        if field.type == "binary" and not is_digit(data.status):
            continue
        print(item.name, data.type, data.status)
        await setValue(item.name, data.type, data.status)
    return FunctionRespons(status=TypeRespons.OK, data="ok")
コード例 #4
0
def dleteDevicesFromGroups(systemName: str):
    groups = Groups.all()
    for group in groups:
        group.devices = list(
            filter(lambda device: device.name != systemName, group.devices))
        group.save()
コード例 #5
0
async def get_group(data: GroupSchema):
    res = Groups.create(data)
    if res:
        return "ok"
    return JSONResponse(status_code=400,
                        content={"message": "error add group"})
コード例 #6
0
async def get_group(name: str, auth_data: dict = Depends(token_dep)):
    return Groups.get(name)
コード例 #7
0
async def get_group(auth_data: dict = Depends(token_dep)):
    groups = []
    for item in Groups.all():
        groups.append(item)
    return groups