def __exit__(self, exc_type, exc_val, exc_tb): _src = self._src_view self._dot_view = self._dot_view.to_dict() _diffs = diff(self._dot_view_old, self._dot_view) for op, path, old, new in _diffs: path = [self._attr_map.get(p, p) for p in path] deep_set(_src, path, new)
def __exit__(self, typ, value, traceback): # diff and apply _root = self._root_view _diffs = diff(self._old, self._new) for op, path, old, new in _diffs: nsn = path[0] if nsn == "root": deep_set(_root, ".".join(path[1:]), new) else: typ = self._nsn_gvr[nsn] nsn = util.normalized_nsn(nsn) path = ["mount", typ, nsn, "spec"] + list(path[1:]) deep_set(_root, path, new)
def __exit__(self, typ, value, traceback): _root = self._root_view _diffs = diff(self._old, self._new) for op, path, old, new in _diffs: typ = path[0] if typ == "root": deep_set(_root, ".".join(path[1:]), new) else: typ = self._typ_full_typ[typ] nsn = util.normalized_nsn(path[1]) path = ["mount", typ, nsn, "spec"] + list(path[2:]) deep_set(_root, path, new)
def h(parent, mounts): home = parent mode = deep_get(home, "control.mode.intent") if mode is None: return objects = dict() # handle rooms rooms = mounts.get(room_gvr, {}) # check all room's mode _path = "control.mode.status" if len(rooms) == 0: deep_get(home, _path) elif all( deep_get(r, "spec." + _path) == mode_config[mode]["rooms"]["mode"] for _, r in rooms.items()): deep_set(home, _path, mode) elif mode == "normal": deep_set(home, _path, "normal") else: deep_set(home, _path, "undef") # check objects in room for n, r in rooms.items(): for o, _ in deep_get(r, "obs.objects", {}).items(): objects[n] = {"location": n} ... deep_set(home, "obs.objects", objects)
def do_mode_lamps(parent, mounts): room, devices = parent, mounts mode = deep_get(room, "control.mode.intent") if mode is None: return _config = mode_config[mode]["lamps"] _bright = list() for lt in [ul_gvr, cl_gvr]: _pc = lamp_converters[lt]["power"]["to"] _bc = lamp_converters[lt]["brightness"]["to"] # iterate over individual lamp for n, _l in devices.get(lt, {}).items(): _p = deep_get(_l, "spec.control.power.intent") _b = deep_get(_l, "spec.control.brightness.intent", 0) # set power if "power" in _config: deep_set(_l, "spec.control.power.intent", _pc(_config["power"])) # add brightness if _pc(_p) == "on": _bright.append(_bc(_b)) if "brightness" in _config: _max = _config["brightness"].get("max", 1) _min = _config["brightness"].get("min", 0) # reset the lamps' brightness only when they # don't fit the mode if not (_min <= sum(_bright) <= _max) and len(_bright) > 0: _bright = deep_get(room, "control.brightness.intent") if _min <= _bright <= _max: _bright_div = _bright else: _bright_div = (_max + _min) / 2 / len(_bright) _set_bright(devices, _bright_div)
def h(parent, mounts): room, devices = parent, mounts mode = deep_get(room, "control.mode.intent") _config = mode_config[mode]["lamps"] # handle mode and brightness matched = True _bright = 0 for lt in [ul_gvr, cl_gvr]: _pc = lamp_converters[lt]["power"]["from"] _bc = lamp_converters[lt]["brightness"]["from"] # iterate over individual lamp for n, _l in devices.get(lt, {}).items(): if "spec" not in _l: continue _l = _l["spec"] _p = deep_get(_l, "control.power.status", None) _b = deep_get(_l, "control.brightness.status", 0) # check power if "power" in _config and _config["power"] != _pc(_p): matched = False # add brightness if _pc(_p) == "on": _bright += _bc(_b) deep_set(room, f"control.brightness.status", _bright) if "brightness" in _config: _max = _config["brightness"].get("max", 1) _min = _config["brightness"].get("min", 0) if not (_min <= _bright <= _max): matched = False # other devices ... deep_set(room, f"control.mode.status", mode if matched else "undef")
def h(sv, pv): for _attr, _ in sv.items(): deep_set(pv, f"control.{_attr}.status", deep_get(pv, f"control.{_attr}.intent"))
def _set_bright(ds, b): for lt in [ul_gvr, cl_gvr]: _lc = lamp_converters[lt]["brightness"]["to"] for _, _l in ds.get(lt, {}).items(): deep_set(_l, "spec.control.brightness.intent", _lc(b))
def h(pv): deep_set(pv, "obs.battery_level", "100%", create=True)