Kaynağa Gözat

Standardise line-ends in recent changed files.

Some tool in the toolchain was inserting an extra CR on save on a
random line, which ruff took exception to.  But running ruff format
on the file causes all the line ends to change except that one line it
was complaining about in check mode.
Jason Rumney 1 yıl önce
ebeveyn
işleme
2d205a4cd4
2 değiştirilmiş dosya ile 2765 ekleme ve 2765 silme
  1. 1085 1085
      custom_components/tuya_local/helpers/device_config.py
  2. 1680 1680
      tests/const.py

+ 1085 - 1085
custom_components/tuya_local/helpers/device_config.py

@@ -1,1085 +1,1085 @@
-"""
-Config parser for Tuya Local devices.
-"""
-
-import logging
-from base64 import b64decode, b64encode
-from collections.abc import Sequence
-from datetime import datetime
-from fnmatch import fnmatch
-from numbers import Number
-from os import walk
-from os.path import dirname, exists, join, splitext
-
-from homeassistant.util import slugify
-from homeassistant.util.yaml import load_yaml
-
-import custom_components.tuya_local.devices as config_dir
-
-_LOGGER = logging.getLogger(__name__)
-
-
-def _typematch(vtype, value):
-    # Workaround annoying legacy of bool being a subclass of int in Python
-    if vtype is int and isinstance(value, bool):
-        return False
-
-    # Allow integers to pass as floats.
-    if vtype is float and isinstance(value, Number):
-        return True
-
-    if isinstance(value, vtype):
-        return True
-    # Allow values embedded in strings if they can be converted
-    # But not for bool, as everything can be converted to bool
-    elif isinstance(value, str) and vtype is not bool:
-        try:
-            vtype(value)
-            return True
-        except ValueError:
-            return False
-    return False
-
-
-def _scale_range(r, s):
-    "Scale range r by factor s"
-    return (r["min"] / s, r["max"] / s)
-
-
-_unsigned_fmts = {
-    1: "B",
-    2: "H",
-    3: "3s",
-    4: "I",
-}
-
-_signed_fmts = {
-    1: "b",
-    2: "h",
-    3: "3s",
-    4: "i",
-}
-
-
-def _bytes_to_fmt(bytes, signed=False):
-    """Convert a byte count to an unpack format."""
-    fmt = _signed_fmts if signed else _unsigned_fmts
-
-    if bytes in fmt:
-        return fmt[bytes]
-    else:
-        return f"{bytes}s"
-
-
-def _equal_or_in(value1, values2):
-    """Return true if value1 is the same as values2, or appears in values2."""
-    if not isinstance(values2, str) and isinstance(values2, Sequence):
-        return value1 in values2
-    else:
-        return value1 == values2
-
-
-def _remove_duplicates(seq):
-    """Remove dulicates from seq, maintaining order."""
-    if not seq:
-        return []
-    seen = set()
-    adder = seen.add
-    return [x for x in seq if not (x in seen or adder(x))]
-
-
-class TuyaDeviceConfig:
-    """Representation of a device config for Tuya Local devices."""
-
-    def __init__(self, fname):
-        """Initialize the device config.
-        Args:
-            fname (string): The filename of the yaml config to load."""
-        _CONFIG_DIR = dirname(config_dir.__file__)
-        self._fname = fname
-        filename = join(_CONFIG_DIR, fname)
-        self._config = load_yaml(filename)
-        _LOGGER.debug("Loaded device config %s", fname)
-
-    @property
-    def name(self):
-        """Return the friendly name for this device."""
-        return self._config["name"]
-
-    @property
-    def config(self):
-        """Return the config file associated with this device."""
-        return self._fname
-
-    @property
-    def config_type(self):
-        """Return the config type associated with this device."""
-        return splitext(self._fname)[0]
-
-    @property
-    def legacy_type(self):
-        """Return the legacy conf_type associated with this device."""
-        return self._config.get("legacy_type", self.config_type)
-
-    @property
-    def primary_entity(self):
-        """Return the primary type of entity for this device."""
-        return TuyaEntityConfig(
-            self,
-            self._config["primary_entity"],
-            primary=True,
-        )
-
-    def secondary_entities(self):
-        """Iterate through entites for any secondary entites supported."""
-        for conf in self._config.get("secondary_entities", {}):
-            yield TuyaEntityConfig(self, conf)
-
-    def all_entities(self):
-        """Iterate through all entities for this device."""
-        yield self.primary_entity
-        for e in self.secondary_entities():
-            yield e
-
-    def matches(self, dps, product_ids):
-        """Determine whether this config matches the provided dps map or
-        product ids."""
-        product_match = False
-        if product_ids:
-            for p in self._config.get("products", []):
-                if p.get("id", "MISSING_ID!?!") in product_ids:
-                    product_match = True
-
-        required_dps = self._get_required_dps()
-
-        missing_dps = [dp for dp in required_dps if dp.id not in dps.keys()]
-        if len(missing_dps) > 0:
-            _LOGGER.debug(
-                "Not match for %s, missing required DPs: %s",
-                self.name,
-                [{dp.id: dp.type.__name__} for dp in missing_dps],
-            )
-
-        incorrect_type_dps = [
-            dp
-            for dp in self._get_all_dps()
-            if dp.id in dps.keys() and not _typematch(dp.type, dps[dp.id])
-        ]
-        if len(incorrect_type_dps) > 0:
-            _LOGGER.debug(
-                "Not match for %s, DPs have incorrect type: %s",
-                self.name,
-                [{dp.id: dp.type.__name__} for dp in incorrect_type_dps],
-            )
-            if product_match:
-                _LOGGER.warning(
-                    "Product matches %s but dps mismatched",
-                    self.name,
-                )
-            return False
-
-        return product_match or len(missing_dps) == 0
-
-    def _get_all_dps(self):
-        all_dps_list = []
-        all_dps_list += [d for dev in self.all_entities() for d in dev.dps()]
-        return all_dps_list
-
-    def _get_required_dps(self):
-        required_dps_list = [d for d in self._get_all_dps() if not d.optional]
-        return required_dps_list
-
-    def _entity_match_analyse(self, entity, keys, matched, dps):
-        """
-        Determine whether this entity can be a match for the dps
-          Args:
-            entity - the TuyaEntityConfig to check against
-            keys - the unmatched keys for the device
-            matched - the matched keys for the device
-            dps - the dps values to be matched
-        Side Effects:
-            Moves items from keys to matched if they match dps
-        Return Value:
-            True if all dps in entity could be matched to dps, False otherwise
-        """
-        all_dp = keys + matched
-        for d in entity.dps():
-            if (d.id not in all_dp and not d.optional) or (
-                d.id in all_dp and not _typematch(d.type, dps[d.id])
-            ):
-                return False
-            if d.id in keys:
-                matched.append(d.id)
-                keys.remove(d.id)
-        return True
-
-    def match_quality(self, dps, product_ids=None):
-        """Determine the match quality for the provided dps map and product ids."""
-        product_match = 0
-        if product_ids:
-            for p in self._config.get("products", []):
-                if p.get("id", "MISSING_ID!?!") in product_ids:
-                    product_match = 100
-
-        keys = list(dps.keys())
-        matched = []
-        if "updated_at" in keys:
-            keys.remove("updated_at")
-        total = len(keys)
-        if total < 1:
-            return product_match
-
-        for e in self.all_entities():
-            if not self._entity_match_analyse(e, keys, matched, dps):
-                return 0
-
-        return product_match or round((total - len(keys)) * 100 / total)
-
-
-class TuyaEntityConfig:
-    """Representation of an entity config for a supported entity."""
-
-    def __init__(self, device, config, primary=False):
-        self._device = device
-        self._config = config
-        self._is_primary = primary
-
-    @property
-    def name(self):
-        """The friendly name for this entity."""
-        return self._config.get("name")
-
-    @property
-    def translation_key(self):
-        """The translation key for this entity."""
-        return self._config.get("translation_key", self.device_class)
-
-    @property
-    def translation_only_key(self):
-        """The translation key for this entity, not used for unique_id"""
-        return self._config.get("translation_only_key")
-
-    @property
-    def translation_placeholders(self):
-        """The translation placeholders for this entity."""
-        return self._config.get("translation_placeholders", {})
-
-    def unique_id(self, device_uid):
-        """Return a suitable unique_id for this entity."""
-        return f"{device_uid}-{slugify(self.config_id)}"
-
-    @property
-    def entity_category(self):
-        return self._config.get("category")
-
-    @property
-    def deprecated(self):
-        """Return whether this entity is deprecated."""
-        return "deprecated" in self._config.keys()
-
-    @property
-    def deprecation_message(self):
-        """Return a deprecation message for this entity"""
-        replacement = self._config.get(
-            "deprecated", "nothing, this warning has been raised in error"
-        )
-        return (
-            f"The use of {self.entity} for {self._device.name} is "
-            f"deprecated and should be replaced by {replacement}."
-        )
-
-    @property
-    def entity(self):
-        """The entity type of this entity."""
-        return self._config["entity"]
-
-    @property
-    def config_id(self):
-        """The identifier for this entity in the config."""
-        own_name = self._config.get("name")
-        if own_name:
-            return f"{self.entity}_{slugify(own_name)}"
-        if self.translation_key:
-            slug = f"{self.entity}_{self.translation_key}"
-            for key, value in self.translation_placeholders.items():
-                if key in slug:
-                    slug = slug.replace(key, slugify(value))
-                else:
-                    slug = f"{slug}_{value}"
-            return slug
-        return self.entity
-
-    @property
-    def device_class(self):
-        """The device class of this entity."""
-        return self._config.get("class")
-
-    def icon(self, device):
-        """Return the icon for this entity, with state as given."""
-        icon = self._config.get("icon", None)
-        priority = self._config.get("icon_priority", 100)
-
-        for d in self.dps():
-            rule = d.icon_rule(device)
-            if rule and rule["priority"] < priority:
-                icon = rule["icon"]
-                priority = rule["priority"]
-        return icon
-
-    @property
-    def mode(self):
-        """Return the mode (used by Number entities)."""
-        return self._config.get("mode")
-
-    def dps(self):
-        """Iterate through the list of dps for this entity."""
-        for d in self._config["dps"]:
-            yield TuyaDpsConfig(self, d)
-
-    def find_dps(self, name):
-        """Find a dps with the specified name."""
-        for d in self.dps():
-            if d.name == name:
-                return d
-        return None
-
-    def available(self, device):
-        """Return whether this entity should be available, with state as given."""
-        avail_dp = self.find_dps("available")
-        if avail_dp and device.has_returned_state:
-            return avail_dp.get_value(device)
-        return True
-
-
-class TuyaDpsConfig:
-    """Representation of a dps config."""
-
-    def __init__(self, entity, config):
-        self._entity = entity
-        self._config = config
-        self.stringify = False
-
-    @property
-    def id(self):
-        return str(self._config["id"])
-
-    @property
-    def type(self):
-        t = self._config["type"]
-        types = {
-            "boolean": bool,
-            "integer": int,
-            "string": str,
-            "float": float,
-            "bitfield": int,
-            "json": str,
-            "base64": str,
-            "utf16b64": str,
-            "hex": str,
-            "unixtime": int,
-        }
-        return types.get(t)
-
-    @property
-    def rawtype(self):
-        return self._config["type"]
-
-    @property
-    def name(self):
-        return self._config["name"]
-
-    @property
-    def optional(self):
-        return self._config.get("optional", False)
-
-    @property
-    def persist(self):
-        return self._config.get("persist", True)
-
-    @property
-    def force(self):
-        return self._config.get("force", False)
-
-    @property
-    def sensitive(self):
-        return self._config.get("sensitive", False)
-
-    @property
-    def format(self):
-        fmt = self._config.get("format")
-        if fmt:
-            unpack_fmt = ">"
-            ranges = []
-            names = []
-            for f in fmt:
-                name = f.get("name")
-                b = f.get("bytes", 1)
-                r = f.get("range")
-                if r:
-                    mn = r.get("min")
-                    mx = r.get("max")
-                else:
-                    mn = 0
-                    mx = 256**b - 1
-
-                unpack_fmt = unpack_fmt + _bytes_to_fmt(b, mn < 0)
-                ranges.append({"min": mn, "max": mx})
-                names.append(name)
-            _LOGGER.debug("format of %s found", unpack_fmt)
-            return {"format": unpack_fmt, "ranges": ranges, "names": names}
-
-        return None
-
-    @property
-    def mask(self):
-        mask = self._config.get("mask")
-        if mask:
-            return int(mask, 16)
-
-    @property
-    def endianness(self):
-        endianness = self._config.get("endianness", "big")
-        return endianness
-
-    def get_value(self, device):
-        """Return the value of the dps from the given device."""
-        mask = self.mask
-        bytevalue = self.decoded_value(device)
-        if mask and isinstance(bytevalue, bytes):
-            value = int.from_bytes(bytevalue, self.endianness)
-            scale = mask & (1 + ~mask)
-            return self._map_from_dps((value & mask) // scale, device)
-        else:
-            return self._map_from_dps(device.get_property(self.id), device)
-
-    def decoded_value(self, device):
-        v = self._map_from_dps(device.get_property(self.id), device)
-        if self.rawtype == "hex" and isinstance(v, str):
-            try:
-                return bytes.fromhex(v)
-            except ValueError:
-                _LOGGER.warning(
-                    "%s sent invalid hex '%s' for %s",
-                    device.name,
-                    v,
-                    self.name,
-                )
-                return None
-
-        elif self.rawtype == "base64" and isinstance(v, str):
-            try:
-                return b64decode(v)
-            except ValueError:
-                _LOGGER.warning(
-                    "%s sent invalid base64 '%s' for %s",
-                    device.name,
-                    v,
-                    self.name,
-                )
-                return None
-        else:
-            return v
-
-    def encode_value(self, v):
-        if self.rawtype == "hex":
-            return v.hex()
-        elif self.rawtype == "base64":
-            return b64encode(v).decode("utf-8")
-        elif self.rawtype == "unixtime" and isinstance(v, datetime):
-            return v.timestamp()
-        else:
-            return v
-
-    def _match(self, matchdata, value):
-        """Return true val1 matches val2"""
-        if self.rawtype == "bitfield" and matchdata:
-            try:
-                return (int(value) & int(matchdata)) != 0
-            except (TypeError, ValueError):
-                return False
-        else:
-            return str(value) == str(matchdata)
-
-    async def async_set_value(self, device, value):
-        """Set the value of the dps in the given device to given value."""
-        if self.readonly:
-            raise TypeError(f"{self.name} is read only")
-        if self.invalid_for(value, device):
-            raise AttributeError(f"{self.name} cannot be set at this time")
-        settings = self.get_values_to_set(device, value)
-        await device.async_set_properties(settings)
-
-    def mapping_available(self, mapping, device):
-        """Determine if this mapping should be available."""
-        if "available" in mapping:
-            avail_dp = self._entity.find_dps(mapping.get("available"))
-            if avail_dp:
-                return avail_dp.get_value(device)

-
-        return True
-
-    def should_show_mapping(self, mapping, device):
-        """Determine if this mapping should be shown in the list of values."""
-        if "value" not in mapping or mapping.get("hidden", False):
-            return False
-        return self.mapping_available(mapping, device)
-
-    def values(self, device):
-        """Return the possible values a dps can take."""
-        if "mapping" not in self._config.keys():
-            return []
-        val = []
-        for m in self._config["mapping"]:
-            if self.should_show_mapping(m, device):
-                val.append(m["value"])
-
-            # If there is mirroring without override, include mirrored values
-            elif "value_mirror" in m:
-                r_dps = self._entity.find_dps(m["value_mirror"])
-                if r_dps:
-                    val = val + r_dps.values(device)
-            for c in m.get("conditions", {}):
-                if self.should_show_mapping(c, device):
-                    val.append(c["value"])
-                elif "value_mirror" in c:
-                    r_dps = self._entity.find_dps(c["value_mirror"])
-                    if r_dps:
-                        val = val + r_dps.values(device)
-
-            cond = self._active_condition(m, device)
-            if cond and "mapping" in cond:
-                c_val = []
-                for m2 in cond["mapping"]:
-                    if self.should_show_mapping(m2, device):
-                        c_val.append(m2["value"])
-
-                    elif "value_mirror" in m:
-                        r_dps = self._entity.find_dps(m["value_mirror"])
-                        if r_dps:
-                            c_val = c_val + r_dps.values(device)
-                # if given, the conditional mapping is an override
-                if c_val:
-                    val = c_val
-                    break
-        return _remove_duplicates(val)
-
-    @property
-    def default(self):
-        """Return the default value for a dp."""
-        if "mapping" not in self._config.keys():
-            _LOGGER.debug(
-                "No mapping for %s, unable to determine default value",
-                self.name,
-            )
-            return None
-        for m in self._config["mapping"]:
-            if m.get("default", False):
-                return m.get("value", m.get("dps_val", None))
-            for c in m.get("conditions", {}):
-                if c.get("default", False):
-                    return c.get("value", m.get("value", m.get("dps_val", None)))
-
-    def range(self, device, scaled=True):
-        """Return the range for this dps if configured."""
-        scale = self.scale(device) if scaled else 1
-        mapping = self._find_map_for_dps(device.get_property(self.id), device)
-        r = self._config.get("range")
-        if mapping:
-            _LOGGER.debug("Considering mapping for range of %s", self.name)
-            cond = self._active_condition(mapping, device)
-            if cond:
-                r = cond.get("range", r)
-
-        if r and "min" in r and "max" in r:
-            return _scale_range(r, scale)
-        else:
-            return None
-
-    def scale(self, device):
-        scale = 1
-        mapping = self._find_map_for_dps(device.get_property(self.id), device)
-        if mapping:
-            scale = mapping.get("scale", 1)
-            cond = self._active_condition(mapping, device)
-            if cond:
-                scale = cond.get("scale", scale)
-        return scale
-
-    def precision(self, device):
-        if self.type is int:
-            scale = self.scale(device)
-            precision = 0
-            while scale > 1.0:
-                scale /= 10.0
-                precision += 1
-            return precision
-
-    @property
-    def suggested_display_precision(self):
-        return self._config.get("precision")
-
-    def step(self, device, scaled=True):
-        step = 1
-        scale = self.scale(device) if scaled else 1
-        mapping = self._find_map_for_dps(device.get_property(self.id), device)
-        if mapping:
-            _LOGGER.debug("Considering mapping for step of %s", self.name)
-            step = mapping.get("step", 1)
-
-            cond = self._active_condition(mapping, device)
-            if cond:
-                constraint = mapping.get("constraint", self.name)
-                _LOGGER.debug("Considering condition on %s", constraint)
-                step = cond.get("step", step)
-        if step != 1 or scale != 1:
-            _LOGGER.debug(
-                "Step for %s is %s with scale %s",
-                self.name,
-                step,
-                scale,
-            )
-        return step / scale if scaled else step
-
-    @property
-    def readonly(self):
-        return self._config.get("readonly", False)
-
-    def invalid_for(self, value, device):
-        mapping = self._find_map_for_value(value, device)
-        if mapping:
-            cond = self._active_condition(mapping, device)
-            if cond:
-                return cond.get("invalid", False)
-        return False
-
-    @property
-    def hidden(self):
-        return self._config.get("hidden", False)
-
-    @property
-    def unit(self):
-        return self._config.get("unit")
-
-    @property
-    def state_class(self):
-        """The state class of this measurement."""
-        return self._config.get("class")
-
-    def _find_map_for_dps(self, value, device):
-        default = None
-        for m in self._config.get("mapping", {}):
-            if not self.mapping_available(m, device) and "conditions" not in m:
-                continue
-            if "dps_val" not in m:
-                default = m
-            elif self._match(m["dps_val"], value):
-                return m
-        return default
-
-    def _correct_type(self, result):
-        """Convert value to the correct type for this dp."""
-        if self.type is int:
-            _LOGGER.debug("Rounding %s", self.name)
-            result = int(round(result))
-        elif self.type is bool:
-            result = True if result else False
-        elif self.type is float:
-            result = float(result)
-        elif self.type is str:
-            result = str(result)
-            if self.rawtype == "utf16b64":
-                result = b64encode(result.encode("utf-16-be")).decode("utf-8")
-
-        if self.stringify:
-            result = str(result)
-
-        return result
-
-    def _map_from_dps(self, val, device):
-        if val is not None and self.type is not str and isinstance(val, str):
-            try:
-                val = self.type(val)
-                self.stringify = True
-            except ValueError:
-                self.stringify = False
-        else:
-            self.stringify = False
-
-        # decode utf-16 base64 strings first, so normal strings can be matched
-        if self.rawtype == "utf16b64" and isinstance(val, str):
-            try:
-                val = b64decode(val).decode("utf-16-be")
-            except ValueError:
-                _LOGGER.warning("Invalid utf16b64 %s", val)
-
-        result = val
-        scale = self.scale(device)
-        replaced = False
-
-        mapping = self._find_map_for_dps(val, device)
-        if mapping:
-            invert = mapping.get("invert", False)
-            redirect = mapping.get("value_redirect")
-            mirror = mapping.get("value_mirror")
-            replaced = "value" in mapping
-            result = mapping.get("value", result)
-            target_range = mapping.get("target_range")
-
-            cond = self._active_condition(mapping, device)
-            if cond:
-                if cond.get("invalid", False):
-                    return None
-                replaced = replaced or "value" in cond
-                result = cond.get("value", result)
-                redirect = cond.get("value_redirect", redirect)
-                mirror = cond.get("value_mirror", mirror)
-                target_range = cond.get("target_range", target_range)
-
-                for m in cond.get("mapping", {}):
-                    if str(m.get("dps_val")) == str(result):
-                        replaced = "value" in m
-                        result = m.get("value", result)
-
-            if redirect:
-                _LOGGER.debug("Redirecting %s to %s", self.name, redirect)
-                r_dps = self._entity.find_dps(redirect)
-                if r_dps:
-                    return r_dps.get_value(device)
-            if mirror:
-                r_dps = self._entity.find_dps(mirror)
-                if r_dps:
-                    return r_dps.get_value(device)
-
-            if invert and isinstance(result, Number):
-                r = self._config.get("range")
-                if r and "min" in r and "max" in r:
-                    result = -1 * result + r["min"] + r["max"]
-                    replaced = True
-
-            if target_range and isinstance(result, Number):
-                r = self._config.get("range")
-                if r and "max" in r and "max" in target_range:
-                    from_min = r.get("min", 0)
-                    from_max = r["max"]
-                    to_min = target_range.get("min", 0)
-                    to_max = target_range["max"]
-                    result = to_min + (
-                        (result - from_min) * (to_max - to_min) / (from_max - from_min)
-                    )
-                    replaced = True
-
-            if scale != 1 and isinstance(result, Number):
-                result = result / scale
-                replaced = True
-
-        if self.rawtype == "unixtime" and isinstance(result, int):
-            try:
-                result = datetime.fromtimestamp(result)
-                replaced = True
-            except Exception:
-                _LOGGER.warning("Invalid timestamp %d", result)
-
-        if replaced:
-            _LOGGER.debug(
-                "%s: Mapped dps %s value from %s to %s",
-                self._entity._device.name,
-                self.id,
-                val,
-                result,
-            )
-
-        return result
-
-    def _find_map_for_value(self, value, device):
-        default = None
-        nearest = None
-        distance = float("inf")
-        for m in self._config.get("mapping", {}):
-            if "dps_val" not in m:
-                default = m
-            # The following avoids further matching on the above case
-            # and in the null mapping case, which is intended to be
-            # a one-way map to prevent the entity showing as unavailable
-            # when no value is being reported by the device.
-            if m.get("dps_val") is None:
-                continue
-            if "value" in m and str(m["value"]) == str(value):
-                return m
-            if (
-                "value" in m
-                and isinstance(m["value"], Number)
-                and isinstance(value, Number)
-            ):
-                d = abs(m["value"] - value)
-                if d < distance:
-                    distance = d
-                    nearest = m
-
-            if "value" not in m and "value_mirror" in m:
-                r_dps = self._entity.find_dps(m["value_mirror"])
-                if r_dps and str(r_dps.get_value(device)) == str(value):
-                    return m
-
-            for c in m.get("conditions", {}):
-                if "value" in c and str(c["value"]) == str(value):
-                    c_dp = self._entity.find_dps(m.get("constraint", self.name))
-                    # only consider the condition a match if we can change
-                    # the dp to match, or it already matches
-                    if (c_dp and c_dp.id != self.id and not c_dp.readonly) or (
-                        _equal_or_in(
-                            device.get_property(c_dp.id),
-                            c.get("dps_val"),
-                        )
-                    ):
-                        return m
-                if "value" not in c and "value_mirror" in c:
-                    r_dps = self._entity.find_dps(c["value_mirror"])
-                    if r_dps and str(r_dps.get_value(device)) == str(value):
-                        return m
-        if nearest:
-            return nearest
-        return default
-
-    def _active_condition(self, mapping, device, value=None):
-        constraint = mapping.get("constraint", self.name)
-        conditions = mapping.get("conditions")
-        c_match = None
-        if constraint and conditions:
-            c_dps = self._entity.find_dps(constraint)
-            # base64 and hex have to be decoded
-            c_val = (
-                None
-                if c_dps is None
-                else (
-                    c_dps.get_value(device)
-                    if c_dps.rawtype == "base64" or c_dps.rawtype == "hex"
-                    else device.get_property(c_dps.id)
-                )
-            )
-            for cond in conditions:
-                avail_dp = cond.get("available")
-                if avail_dp:
-                    avail_dps = self._entity.find_dps(avail_dp)
-                    if avail_dps and not avail_dps.get_value(device):
-                        continue
-                if c_val is not None and (_equal_or_in(c_val, cond.get("dps_val"))):
-                    c_match = cond
-                # Case where matching None, need extra checks to ensure we
-                # are not just defaulting and it is really a match
-                elif (
-                    c_val is None
-                    and c_dps is not None
-                    and "dps_val" in cond
-                    and cond.get("dps_val") is None
-                ):
-                    c_match = cond
-                # when changing, another condition may become active
-                # return that if it exists over a current condition
-                if value is not None and value == cond.get("value"):
-                    return cond
-
-        return c_match
-
-    def get_values_to_set(self, device, value):
-        """Return the dps values that would be set when setting to value"""
-        result = value
-        dps_map = {}
-        if self.readonly:
-            return dps_map
-
-        mapping = self._find_map_for_value(value, device)
-        scale = self.scale(device)
-        mask = self.mask
-        if mapping:
-            replaced = False
-            redirect = mapping.get("value_redirect")
-            invert = mapping.get("invert", False)
-            target_range = mapping.get("target_range")
-            step = mapping.get("step")
-            if not isinstance(step, Number):
-                step = None
-            if "dps_val" in mapping and not mapping.get("hidden", False):
-                result = mapping["dps_val"]
-                replaced = True
-            # Conditions may have side effect of setting another value.
-            cond = self._active_condition(mapping, device, value)
-            if cond:
-                cval = cond.get("value")
-                if cval is None:
-                    r_dps = cond.get("value_mirror")
-                    if r_dps:
-                        mirror = self._entity.find_dps(r_dps)
-                        if mirror:
-                            cval = mirror.get_value(device)
-
-                if cval == value:
-                    c_dps = self._entity.find_dps(mapping.get("constraint", self.name))
-                    cond_dpsval = cond.get("dps_val")
-                    single_match = isinstance(cond_dpsval, str) or (
-                        not isinstance(cond_dpsval, Sequence)
-                    )
-                    if c_dps and c_dps.id != self.id and single_match:
-                        c_val = c_dps._map_from_dps(
-                            cond.get("dps_val", device.get_property(c_dps.id)),
-                            device,
-                        )
-                        dps_map.update(c_dps.get_values_to_set(device, c_val))
-
-                # Allow simple conditional mapping overrides
-                for m in cond.get("mapping", {}):
-                    if m.get("value") == value and not m.get("hidden", False):
-                        result = m.get("dps_val", result)
-
-                step = cond.get("step", step)
-                redirect = cond.get("value_redirect", redirect)
-                target_range = cond.get("target_range", target_range)
-
-            if redirect:
-                _LOGGER.debug("Redirecting %s to %s", self.name, redirect)
-                r_dps = self._entity.find_dps(redirect)
-                if r_dps:
-                    return r_dps.get_values_to_set(device, value)
-
-            if scale != 1 and isinstance(result, Number):
-                _LOGGER.debug("Scaling %s by %s", result, scale)
-                result = result * scale
-                remap = self._find_map_for_value(result, device)
-                if (
-                    remap
-                    and "dps_val" in remap
-                    and "dps_val" not in mapping
-                    and not remap.get("hidden", False)
-                ):
-                    result = remap["dps_val"]
-                replaced = True
-
-            if target_range and isinstance(result, Number):
-                r = self._config.get("range")
-                if r and "max" in r and "max" in target_range:
-                    from_min = target_range.get("min", 0)
-                    from_max = target_range["max"]
-                    to_min = r.get("min", 0)
-                    to_max = r["max"]
-                    result = to_min + (
-                        (result - from_min) * (to_max - to_min) / (from_max - from_min)
-                    )
-                    replaced = True
-
-            if invert:
-                r = self._config.get("range")
-                if r and "min" in r and "max" in r:
-                    result = -1 * result + r["min"] + r["max"]
-                    replaced = True
-
-            if step and isinstance(result, Number):
-                _LOGGER.debug("Stepping %s to %s", result, step)
-                result = step * round(float(result) / step)
-                remap = self._find_map_for_value(result, device)
-                if (
-                    remap
-                    and "dps_val" in remap
-                    and "dps_val" not in mapping
-                    and not remap.get("hidden", False)
-                ):
-                    result = remap["dps_val"]
-                replaced = True
-
-            if replaced:
-                _LOGGER.debug(
-                    "%s: Mapped dps %s to %s from %s",
-                    self._entity._device.name,
-                    self.id,
-                    result,
-                    value,
-                )
-
-        r = self.range(device, scaled=False)
-        if r and isinstance(result, Number):
-            mn = r[0]
-            mx = r[1]
-            if round(result) < mn or round(result) > mx:
-                # Output scaled values in the error message
-                r = self.range(device, scaled=True)
-                mn = r[0]
-                mx = r[1]
-                raise ValueError(f"{self.name} ({value}) must be between {mn} and {mx}")
-        if mask and isinstance(result, bool):
-            result = int(result)
-
-        if mask and isinstance(result, Number):
-            # mask is in hex, 2 digits/characters per byte
-            hex_mask = self._config.get("mask")
-            length = int(len(hex_mask) / 2)
-            # Convert to int
-            endianness = self.endianness
-            mask_scale = mask & (1 + ~mask)
-            current_value = int.from_bytes(self.decoded_value(device), endianness)
-            result = (current_value & ~mask) | (mask & int(result * mask_scale))
-            result = self.encode_value(result.to_bytes(length, endianness))
-
-        dps_map[self.id] = self._correct_type(result)
-        return dps_map
-
-    def icon_rule(self, device):
-        mapping = self._find_map_for_dps(device.get_property(self.id), device)
-        icon = None
-        priority = 100
-        if mapping:
-            icon = mapping.get("icon", icon)
-            priority = mapping.get("icon_priority", 10 if icon else 100)
-            cond = self._active_condition(mapping, device)
-            if cond and cond.get("icon_priority", 10) < priority:
-                icon = cond.get("icon", icon)
-                priority = cond.get("icon_priority", 10 if icon else 100)
-
-        return {"priority": priority, "icon": icon}
-
-
-def available_configs():
-    """List the available config files."""
-    _CONFIG_DIR = dirname(config_dir.__file__)
-
-    for path, dirs, files in walk(_CONFIG_DIR):
-        for basename in sorted(files):
-            if fnmatch(basename, "*.yaml"):
-                yield basename
-
-
-def possible_matches(dps, product_ids=None):
-    """Return possible matching configs for a given set of
-    dps values and product_ids."""
-    for cfg in available_configs():
-        parsed = TuyaDeviceConfig(cfg)
-        try:
-            if parsed.matches(dps, product_ids):
-                yield parsed
-        except TypeError:
-            _LOGGER.error("Parse error in %s", cfg)
-
-
-def get_config(conf_type):
-    """
-    Return a config to use with config_type.
-    """
-    _CONFIG_DIR = dirname(config_dir.__file__)
-    fname = conf_type + ".yaml"
-    fpath = join(_CONFIG_DIR, fname)
-    if exists(fpath):
-        return TuyaDeviceConfig(fname)
-    else:
-        return config_for_legacy_use(conf_type)
-
-
-def config_for_legacy_use(conf_type):
-    """
-    Return a config to use with config_type for legacy transition.
-    Note: as there are two variants for Kogan Socket, this is not guaranteed
-    to be the correct config for the device, so only use it for looking up
-    the legacy class during the transition period.
-    """
-    for cfg in available_configs():
-        parsed = TuyaDeviceConfig(cfg)
-        if parsed.legacy_type == conf_type:
-            return parsed
-
-    return None
+"""
+Config parser for Tuya Local devices.
+"""
+
+import logging
+from base64 import b64decode, b64encode
+from collections.abc import Sequence
+from datetime import datetime
+from fnmatch import fnmatch
+from numbers import Number
+from os import walk
+from os.path import dirname, exists, join, splitext
+
+from homeassistant.util import slugify
+from homeassistant.util.yaml import load_yaml
+
+import custom_components.tuya_local.devices as config_dir
+
+_LOGGER = logging.getLogger(__name__)
+
+
+def _typematch(vtype, value):
+    # Workaround annoying legacy of bool being a subclass of int in Python
+    if vtype is int and isinstance(value, bool):
+        return False
+
+    # Allow integers to pass as floats.
+    if vtype is float and isinstance(value, Number):
+        return True
+
+    if isinstance(value, vtype):
+        return True
+    # Allow values embedded in strings if they can be converted
+    # But not for bool, as everything can be converted to bool
+    elif isinstance(value, str) and vtype is not bool:
+        try:
+            vtype(value)
+            return True
+        except ValueError:
+            return False
+    return False
+
+
+def _scale_range(r, s):
+    "Scale range r by factor s"
+    return (r["min"] / s, r["max"] / s)
+
+
+_unsigned_fmts = {
+    1: "B",
+    2: "H",
+    3: "3s",
+    4: "I",
+}
+
+_signed_fmts = {
+    1: "b",
+    2: "h",
+    3: "3s",
+    4: "i",
+}
+
+
+def _bytes_to_fmt(bytes, signed=False):
+    """Convert a byte count to an unpack format."""
+    fmt = _signed_fmts if signed else _unsigned_fmts
+
+    if bytes in fmt:
+        return fmt[bytes]
+    else:
+        return f"{bytes}s"
+
+
+def _equal_or_in(value1, values2):
+    """Return true if value1 is the same as values2, or appears in values2."""
+    if not isinstance(values2, str) and isinstance(values2, Sequence):
+        return value1 in values2
+    else:
+        return value1 == values2
+
+
+def _remove_duplicates(seq):
+    """Remove dulicates from seq, maintaining order."""
+    if not seq:
+        return []
+    seen = set()
+    adder = seen.add
+    return [x for x in seq if not (x in seen or adder(x))]
+
+
+class TuyaDeviceConfig:
+    """Representation of a device config for Tuya Local devices."""
+
+    def __init__(self, fname):
+        """Initialize the device config.
+        Args:
+            fname (string): The filename of the yaml config to load."""
+        _CONFIG_DIR = dirname(config_dir.__file__)
+        self._fname = fname
+        filename = join(_CONFIG_DIR, fname)
+        self._config = load_yaml(filename)
+        _LOGGER.debug("Loaded device config %s", fname)
+
+    @property
+    def name(self):
+        """Return the friendly name for this device."""
+        return self._config["name"]
+
+    @property
+    def config(self):
+        """Return the config file associated with this device."""
+        return self._fname
+
+    @property
+    def config_type(self):
+        """Return the config type associated with this device."""
+        return splitext(self._fname)[0]
+
+    @property
+    def legacy_type(self):
+        """Return the legacy conf_type associated with this device."""
+        return self._config.get("legacy_type", self.config_type)
+
+    @property
+    def primary_entity(self):
+        """Return the primary type of entity for this device."""
+        return TuyaEntityConfig(
+            self,
+            self._config["primary_entity"],
+            primary=True,
+        )
+
+    def secondary_entities(self):
+        """Iterate through entites for any secondary entites supported."""
+        for conf in self._config.get("secondary_entities", {}):
+            yield TuyaEntityConfig(self, conf)
+
+    def all_entities(self):
+        """Iterate through all entities for this device."""
+        yield self.primary_entity
+        for e in self.secondary_entities():
+            yield e
+
+    def matches(self, dps, product_ids):
+        """Determine whether this config matches the provided dps map or
+        product ids."""
+        product_match = False
+        if product_ids:
+            for p in self._config.get("products", []):
+                if p.get("id", "MISSING_ID!?!") in product_ids:
+                    product_match = True
+
+        required_dps = self._get_required_dps()
+
+        missing_dps = [dp for dp in required_dps if dp.id not in dps.keys()]
+        if len(missing_dps) > 0:
+            _LOGGER.debug(
+                "Not match for %s, missing required DPs: %s",
+                self.name,
+                [{dp.id: dp.type.__name__} for dp in missing_dps],
+            )
+
+        incorrect_type_dps = [
+            dp
+            for dp in self._get_all_dps()
+            if dp.id in dps.keys() and not _typematch(dp.type, dps[dp.id])
+        ]
+        if len(incorrect_type_dps) > 0:
+            _LOGGER.debug(
+                "Not match for %s, DPs have incorrect type: %s",
+                self.name,
+                [{dp.id: dp.type.__name__} for dp in incorrect_type_dps],
+            )
+            if product_match:
+                _LOGGER.warning(
+                    "Product matches %s but dps mismatched",
+                    self.name,
+                )
+            return False
+
+        return product_match or len(missing_dps) == 0
+
+    def _get_all_dps(self):
+        all_dps_list = []
+        all_dps_list += [d for dev in self.all_entities() for d in dev.dps()]
+        return all_dps_list
+
+    def _get_required_dps(self):
+        required_dps_list = [d for d in self._get_all_dps() if not d.optional]
+        return required_dps_list
+
+    def _entity_match_analyse(self, entity, keys, matched, dps):
+        """
+        Determine whether this entity can be a match for the dps
+          Args:
+            entity - the TuyaEntityConfig to check against
+            keys - the unmatched keys for the device
+            matched - the matched keys for the device
+            dps - the dps values to be matched
+        Side Effects:
+            Moves items from keys to matched if they match dps
+        Return Value:
+            True if all dps in entity could be matched to dps, False otherwise
+        """
+        all_dp = keys + matched
+        for d in entity.dps():
+            if (d.id not in all_dp and not d.optional) or (
+                d.id in all_dp and not _typematch(d.type, dps[d.id])
+            ):
+                return False
+            if d.id in keys:
+                matched.append(d.id)
+                keys.remove(d.id)
+        return True
+
+    def match_quality(self, dps, product_ids=None):
+        """Determine the match quality for the provided dps map and product ids."""
+        product_match = 0
+        if product_ids:
+            for p in self._config.get("products", []):
+                if p.get("id", "MISSING_ID!?!") in product_ids:
+                    product_match = 100
+
+        keys = list(dps.keys())
+        matched = []
+        if "updated_at" in keys:
+            keys.remove("updated_at")
+        total = len(keys)
+        if total < 1:
+            return product_match
+
+        for e in self.all_entities():
+            if not self._entity_match_analyse(e, keys, matched, dps):
+                return 0
+
+        return product_match or round((total - len(keys)) * 100 / total)
+
+
+class TuyaEntityConfig:
+    """Representation of an entity config for a supported entity."""
+
+    def __init__(self, device, config, primary=False):
+        self._device = device
+        self._config = config
+        self._is_primary = primary
+
+    @property
+    def name(self):
+        """The friendly name for this entity."""
+        return self._config.get("name")
+
+    @property
+    def translation_key(self):
+        """The translation key for this entity."""
+        return self._config.get("translation_key", self.device_class)
+
+    @property
+    def translation_only_key(self):
+        """The translation key for this entity, not used for unique_id"""
+        return self._config.get("translation_only_key")
+
+    @property
+    def translation_placeholders(self):
+        """The translation placeholders for this entity."""
+        return self._config.get("translation_placeholders", {})
+
+    def unique_id(self, device_uid):
+        """Return a suitable unique_id for this entity."""
+        return f"{device_uid}-{slugify(self.config_id)}"
+
+    @property
+    def entity_category(self):
+        return self._config.get("category")
+
+    @property
+    def deprecated(self):
+        """Return whether this entity is deprecated."""
+        return "deprecated" in self._config.keys()
+
+    @property
+    def deprecation_message(self):
+        """Return a deprecation message for this entity"""
+        replacement = self._config.get(
+            "deprecated", "nothing, this warning has been raised in error"
+        )
+        return (
+            f"The use of {self.entity} for {self._device.name} is "
+            f"deprecated and should be replaced by {replacement}."
+        )
+
+    @property
+    def entity(self):
+        """The entity type of this entity."""
+        return self._config["entity"]
+
+    @property
+    def config_id(self):
+        """The identifier for this entity in the config."""
+        own_name = self._config.get("name")
+        if own_name:
+            return f"{self.entity}_{slugify(own_name)}"
+        if self.translation_key:
+            slug = f"{self.entity}_{self.translation_key}"
+            for key, value in self.translation_placeholders.items():
+                if key in slug:
+                    slug = slug.replace(key, slugify(value))
+                else:
+                    slug = f"{slug}_{value}"
+            return slug
+        return self.entity
+
+    @property
+    def device_class(self):
+        """The device class of this entity."""
+        return self._config.get("class")
+
+    def icon(self, device):
+        """Return the icon for this entity, with state as given."""
+        icon = self._config.get("icon", None)
+        priority = self._config.get("icon_priority", 100)
+
+        for d in self.dps():
+            rule = d.icon_rule(device)
+            if rule and rule["priority"] < priority:
+                icon = rule["icon"]
+                priority = rule["priority"]
+        return icon
+
+    @property
+    def mode(self):
+        """Return the mode (used by Number entities)."""
+        return self._config.get("mode")
+
+    def dps(self):
+        """Iterate through the list of dps for this entity."""
+        for d in self._config["dps"]:
+            yield TuyaDpsConfig(self, d)
+
+    def find_dps(self, name):
+        """Find a dps with the specified name."""
+        for d in self.dps():
+            if d.name == name:
+                return d
+        return None
+
+    def available(self, device):
+        """Return whether this entity should be available, with state as given."""
+        avail_dp = self.find_dps("available")
+        if avail_dp and device.has_returned_state:
+            return avail_dp.get_value(device)
+        return True
+
+
+class TuyaDpsConfig:
+    """Representation of a dps config."""
+
+    def __init__(self, entity, config):
+        self._entity = entity
+        self._config = config
+        self.stringify = False
+
+    @property
+    def id(self):
+        return str(self._config["id"])
+
+    @property
+    def type(self):
+        t = self._config["type"]
+        types = {
+            "boolean": bool,
+            "integer": int,
+            "string": str,
+            "float": float,
+            "bitfield": int,
+            "json": str,
+            "base64": str,
+            "utf16b64": str,
+            "hex": str,
+            "unixtime": int,
+        }
+        return types.get(t)
+
+    @property
+    def rawtype(self):
+        return self._config["type"]
+
+    @property
+    def name(self):
+        return self._config["name"]
+
+    @property
+    def optional(self):
+        return self._config.get("optional", False)
+
+    @property
+    def persist(self):
+        return self._config.get("persist", True)
+
+    @property
+    def force(self):
+        return self._config.get("force", False)
+
+    @property
+    def sensitive(self):
+        return self._config.get("sensitive", False)
+
+    @property
+    def format(self):
+        fmt = self._config.get("format")
+        if fmt:
+            unpack_fmt = ">"
+            ranges = []
+            names = []
+            for f in fmt:
+                name = f.get("name")
+                b = f.get("bytes", 1)
+                r = f.get("range")
+                if r:
+                    mn = r.get("min")
+                    mx = r.get("max")
+                else:
+                    mn = 0
+                    mx = 256**b - 1
+
+                unpack_fmt = unpack_fmt + _bytes_to_fmt(b, mn < 0)
+                ranges.append({"min": mn, "max": mx})
+                names.append(name)
+            _LOGGER.debug("format of %s found", unpack_fmt)
+            return {"format": unpack_fmt, "ranges": ranges, "names": names}
+
+        return None
+
+    @property
+    def mask(self):
+        mask = self._config.get("mask")
+        if mask:
+            return int(mask, 16)
+
+    @property
+    def endianness(self):
+        endianness = self._config.get("endianness", "big")
+        return endianness
+
+    def get_value(self, device):
+        """Return the value of the dps from the given device."""
+        mask = self.mask
+        bytevalue = self.decoded_value(device)
+        if mask and isinstance(bytevalue, bytes):
+            value = int.from_bytes(bytevalue, self.endianness)
+            scale = mask & (1 + ~mask)
+            return self._map_from_dps((value & mask) // scale, device)
+        else:
+            return self._map_from_dps(device.get_property(self.id), device)
+
+    def decoded_value(self, device):
+        v = self._map_from_dps(device.get_property(self.id), device)
+        if self.rawtype == "hex" and isinstance(v, str):
+            try:
+                return bytes.fromhex(v)
+            except ValueError:
+                _LOGGER.warning(
+                    "%s sent invalid hex '%s' for %s",
+                    device.name,
+                    v,
+                    self.name,
+                )
+                return None
+
+        elif self.rawtype == "base64" and isinstance(v, str):
+            try:
+                return b64decode(v)
+            except ValueError:
+                _LOGGER.warning(
+                    "%s sent invalid base64 '%s' for %s",
+                    device.name,
+                    v,
+                    self.name,
+                )
+                return None
+        else:
+            return v
+
+    def encode_value(self, v):
+        if self.rawtype == "hex":
+            return v.hex()
+        elif self.rawtype == "base64":
+            return b64encode(v).decode("utf-8")
+        elif self.rawtype == "unixtime" and isinstance(v, datetime):
+            return v.timestamp()
+        else:
+            return v
+
+    def _match(self, matchdata, value):
+        """Return true val1 matches val2"""
+        if self.rawtype == "bitfield" and matchdata:
+            try:
+                return (int(value) & int(matchdata)) != 0
+            except (TypeError, ValueError):
+                return False
+        else:
+            return str(value) == str(matchdata)
+
+    async def async_set_value(self, device, value):
+        """Set the value of the dps in the given device to given value."""
+        if self.readonly:
+            raise TypeError(f"{self.name} is read only")
+        if self.invalid_for(value, device):
+            raise AttributeError(f"{self.name} cannot be set at this time")
+        settings = self.get_values_to_set(device, value)
+        await device.async_set_properties(settings)
+
+    def mapping_available(self, mapping, device):
+        """Determine if this mapping should be available."""
+        if "available" in mapping:
+            avail_dp = self._entity.find_dps(mapping.get("available"))
+            if avail_dp:
+                return avail_dp.get_value(device)
+
+        return True
+
+    def should_show_mapping(self, mapping, device):
+        """Determine if this mapping should be shown in the list of values."""
+        if "value" not in mapping or mapping.get("hidden", False):
+            return False
+        return self.mapping_available(mapping, device)
+
+    def values(self, device):
+        """Return the possible values a dps can take."""
+        if "mapping" not in self._config.keys():
+            return []
+        val = []
+        for m in self._config["mapping"]:
+            if self.should_show_mapping(m, device):
+                val.append(m["value"])
+
+            # If there is mirroring without override, include mirrored values
+            elif "value_mirror" in m:
+                r_dps = self._entity.find_dps(m["value_mirror"])
+                if r_dps:
+                    val = val + r_dps.values(device)
+            for c in m.get("conditions", {}):
+                if self.should_show_mapping(c, device):
+                    val.append(c["value"])
+                elif "value_mirror" in c:
+                    r_dps = self._entity.find_dps(c["value_mirror"])
+                    if r_dps:
+                        val = val + r_dps.values(device)
+
+            cond = self._active_condition(m, device)
+            if cond and "mapping" in cond:
+                c_val = []
+                for m2 in cond["mapping"]:
+                    if self.should_show_mapping(m2, device):
+                        c_val.append(m2["value"])
+
+                    elif "value_mirror" in m:
+                        r_dps = self._entity.find_dps(m["value_mirror"])
+                        if r_dps:
+                            c_val = c_val + r_dps.values(device)
+                # if given, the conditional mapping is an override
+                if c_val:
+                    val = c_val
+                    break
+        return _remove_duplicates(val)
+
+    @property
+    def default(self):
+        """Return the default value for a dp."""
+        if "mapping" not in self._config.keys():
+            _LOGGER.debug(
+                "No mapping for %s, unable to determine default value",
+                self.name,
+            )
+            return None
+        for m in self._config["mapping"]:
+            if m.get("default", False):
+                return m.get("value", m.get("dps_val", None))
+            for c in m.get("conditions", {}):
+                if c.get("default", False):
+                    return c.get("value", m.get("value", m.get("dps_val", None)))
+
+    def range(self, device, scaled=True):
+        """Return the range for this dps if configured."""
+        scale = self.scale(device) if scaled else 1
+        mapping = self._find_map_for_dps(device.get_property(self.id), device)
+        r = self._config.get("range")
+        if mapping:
+            _LOGGER.debug("Considering mapping for range of %s", self.name)
+            cond = self._active_condition(mapping, device)
+            if cond:
+                r = cond.get("range", r)
+
+        if r and "min" in r and "max" in r:
+            return _scale_range(r, scale)
+        else:
+            return None
+
+    def scale(self, device):
+        scale = 1
+        mapping = self._find_map_for_dps(device.get_property(self.id), device)
+        if mapping:
+            scale = mapping.get("scale", 1)
+            cond = self._active_condition(mapping, device)
+            if cond:
+                scale = cond.get("scale", scale)
+        return scale
+
+    def precision(self, device):
+        if self.type is int:
+            scale = self.scale(device)
+            precision = 0
+            while scale > 1.0:
+                scale /= 10.0
+                precision += 1
+            return precision
+
+    @property
+    def suggested_display_precision(self):
+        return self._config.get("precision")
+
+    def step(self, device, scaled=True):
+        step = 1
+        scale = self.scale(device) if scaled else 1
+        mapping = self._find_map_for_dps(device.get_property(self.id), device)
+        if mapping:
+            _LOGGER.debug("Considering mapping for step of %s", self.name)
+            step = mapping.get("step", 1)
+
+            cond = self._active_condition(mapping, device)
+            if cond:
+                constraint = mapping.get("constraint", self.name)
+                _LOGGER.debug("Considering condition on %s", constraint)
+                step = cond.get("step", step)
+        if step != 1 or scale != 1:
+            _LOGGER.debug(
+                "Step for %s is %s with scale %s",
+                self.name,
+                step,
+                scale,
+            )
+        return step / scale if scaled else step
+
+    @property
+    def readonly(self):
+        return self._config.get("readonly", False)
+
+    def invalid_for(self, value, device):
+        mapping = self._find_map_for_value(value, device)
+        if mapping:
+            cond = self._active_condition(mapping, device)
+            if cond:
+                return cond.get("invalid", False)
+        return False
+
+    @property
+    def hidden(self):
+        return self._config.get("hidden", False)
+
+    @property
+    def unit(self):
+        return self._config.get("unit")
+
+    @property
+    def state_class(self):
+        """The state class of this measurement."""
+        return self._config.get("class")
+
+    def _find_map_for_dps(self, value, device):
+        default = None
+        for m in self._config.get("mapping", {}):
+            if not self.mapping_available(m, device) and "conditions" not in m:
+                continue
+            if "dps_val" not in m:
+                default = m
+            elif self._match(m["dps_val"], value):
+                return m
+        return default
+
+    def _correct_type(self, result):
+        """Convert value to the correct type for this dp."""
+        if self.type is int:
+            _LOGGER.debug("Rounding %s", self.name)
+            result = int(round(result))
+        elif self.type is bool:
+            result = True if result else False
+        elif self.type is float:
+            result = float(result)
+        elif self.type is str:
+            result = str(result)
+            if self.rawtype == "utf16b64":
+                result = b64encode(result.encode("utf-16-be")).decode("utf-8")
+
+        if self.stringify:
+            result = str(result)
+
+        return result
+
+    def _map_from_dps(self, val, device):
+        if val is not None and self.type is not str and isinstance(val, str):
+            try:
+                val = self.type(val)
+                self.stringify = True
+            except ValueError:
+                self.stringify = False
+        else:
+            self.stringify = False
+
+        # decode utf-16 base64 strings first, so normal strings can be matched
+        if self.rawtype == "utf16b64" and isinstance(val, str):
+            try:
+                val = b64decode(val).decode("utf-16-be")
+            except ValueError:
+                _LOGGER.warning("Invalid utf16b64 %s", val)
+
+        result = val
+        scale = self.scale(device)
+        replaced = False
+
+        mapping = self._find_map_for_dps(val, device)
+        if mapping:
+            invert = mapping.get("invert", False)
+            redirect = mapping.get("value_redirect")
+            mirror = mapping.get("value_mirror")
+            replaced = "value" in mapping
+            result = mapping.get("value", result)
+            target_range = mapping.get("target_range")
+
+            cond = self._active_condition(mapping, device)
+            if cond:
+                if cond.get("invalid", False):
+                    return None
+                replaced = replaced or "value" in cond
+                result = cond.get("value", result)
+                redirect = cond.get("value_redirect", redirect)
+                mirror = cond.get("value_mirror", mirror)
+                target_range = cond.get("target_range", target_range)
+
+                for m in cond.get("mapping", {}):
+                    if str(m.get("dps_val")) == str(result):
+                        replaced = "value" in m
+                        result = m.get("value", result)
+
+            if redirect:
+                _LOGGER.debug("Redirecting %s to %s", self.name, redirect)
+                r_dps = self._entity.find_dps(redirect)
+                if r_dps:
+                    return r_dps.get_value(device)
+            if mirror:
+                r_dps = self._entity.find_dps(mirror)
+                if r_dps:
+                    return r_dps.get_value(device)
+
+            if invert and isinstance(result, Number):
+                r = self._config.get("range")
+                if r and "min" in r and "max" in r:
+                    result = -1 * result + r["min"] + r["max"]
+                    replaced = True
+
+            if target_range and isinstance(result, Number):
+                r = self._config.get("range")
+                if r and "max" in r and "max" in target_range:
+                    from_min = r.get("min", 0)
+                    from_max = r["max"]
+                    to_min = target_range.get("min", 0)
+                    to_max = target_range["max"]
+                    result = to_min + (
+                        (result - from_min) * (to_max - to_min) / (from_max - from_min)
+                    )
+                    replaced = True
+
+            if scale != 1 and isinstance(result, Number):
+                result = result / scale
+                replaced = True
+
+        if self.rawtype == "unixtime" and isinstance(result, int):
+            try:
+                result = datetime.fromtimestamp(result)
+                replaced = True
+            except Exception:
+                _LOGGER.warning("Invalid timestamp %d", result)
+
+        if replaced:
+            _LOGGER.debug(
+                "%s: Mapped dps %s value from %s to %s",
+                self._entity._device.name,
+                self.id,
+                val,
+                result,
+            )
+
+        return result
+
+    def _find_map_for_value(self, value, device):
+        default = None
+        nearest = None
+        distance = float("inf")
+        for m in self._config.get("mapping", {}):
+            if "dps_val" not in m:
+                default = m
+            # The following avoids further matching on the above case
+            # and in the null mapping case, which is intended to be
+            # a one-way map to prevent the entity showing as unavailable
+            # when no value is being reported by the device.
+            if m.get("dps_val") is None:
+                continue
+            if "value" in m and str(m["value"]) == str(value):
+                return m
+            if (
+                "value" in m
+                and isinstance(m["value"], Number)
+                and isinstance(value, Number)
+            ):
+                d = abs(m["value"] - value)
+                if d < distance:
+                    distance = d
+                    nearest = m
+
+            if "value" not in m and "value_mirror" in m:
+                r_dps = self._entity.find_dps(m["value_mirror"])
+                if r_dps and str(r_dps.get_value(device)) == str(value):
+                    return m
+
+            for c in m.get("conditions", {}):
+                if "value" in c and str(c["value"]) == str(value):
+                    c_dp = self._entity.find_dps(m.get("constraint", self.name))
+                    # only consider the condition a match if we can change
+                    # the dp to match, or it already matches
+                    if (c_dp and c_dp.id != self.id and not c_dp.readonly) or (
+                        _equal_or_in(
+                            device.get_property(c_dp.id),
+                            c.get("dps_val"),
+                        )
+                    ):
+                        return m
+                if "value" not in c and "value_mirror" in c:
+                    r_dps = self._entity.find_dps(c["value_mirror"])
+                    if r_dps and str(r_dps.get_value(device)) == str(value):
+                        return m
+        if nearest:
+            return nearest
+        return default
+
+    def _active_condition(self, mapping, device, value=None):
+        constraint = mapping.get("constraint", self.name)
+        conditions = mapping.get("conditions")
+        c_match = None
+        if constraint and conditions:
+            c_dps = self._entity.find_dps(constraint)
+            # base64 and hex have to be decoded
+            c_val = (
+                None
+                if c_dps is None
+                else (
+                    c_dps.get_value(device)
+                    if c_dps.rawtype == "base64" or c_dps.rawtype == "hex"
+                    else device.get_property(c_dps.id)
+                )
+            )
+            for cond in conditions:
+                avail_dp = cond.get("available")
+                if avail_dp:
+                    avail_dps = self._entity.find_dps(avail_dp)
+                    if avail_dps and not avail_dps.get_value(device):
+                        continue
+                if c_val is not None and (_equal_or_in(c_val, cond.get("dps_val"))):
+                    c_match = cond
+                # Case where matching None, need extra checks to ensure we
+                # are not just defaulting and it is really a match
+                elif (
+                    c_val is None
+                    and c_dps is not None
+                    and "dps_val" in cond
+                    and cond.get("dps_val") is None
+                ):
+                    c_match = cond
+                # when changing, another condition may become active
+                # return that if it exists over a current condition
+                if value is not None and value == cond.get("value"):
+                    return cond
+
+        return c_match
+
+    def get_values_to_set(self, device, value):
+        """Return the dps values that would be set when setting to value"""
+        result = value
+        dps_map = {}
+        if self.readonly:
+            return dps_map
+
+        mapping = self._find_map_for_value(value, device)
+        scale = self.scale(device)
+        mask = self.mask
+        if mapping:
+            replaced = False
+            redirect = mapping.get("value_redirect")
+            invert = mapping.get("invert", False)
+            target_range = mapping.get("target_range")
+            step = mapping.get("step")
+            if not isinstance(step, Number):
+                step = None
+            if "dps_val" in mapping and not mapping.get("hidden", False):
+                result = mapping["dps_val"]
+                replaced = True
+            # Conditions may have side effect of setting another value.
+            cond = self._active_condition(mapping, device, value)
+            if cond:
+                cval = cond.get("value")
+                if cval is None:
+                    r_dps = cond.get("value_mirror")
+                    if r_dps:
+                        mirror = self._entity.find_dps(r_dps)
+                        if mirror:
+                            cval = mirror.get_value(device)
+
+                if cval == value:
+                    c_dps = self._entity.find_dps(mapping.get("constraint", self.name))
+                    cond_dpsval = cond.get("dps_val")
+                    single_match = isinstance(cond_dpsval, str) or (
+                        not isinstance(cond_dpsval, Sequence)
+                    )
+                    if c_dps and c_dps.id != self.id and single_match:
+                        c_val = c_dps._map_from_dps(
+                            cond.get("dps_val", device.get_property(c_dps.id)),
+                            device,
+                        )
+                        dps_map.update(c_dps.get_values_to_set(device, c_val))
+
+                # Allow simple conditional mapping overrides
+                for m in cond.get("mapping", {}):
+                    if m.get("value") == value and not m.get("hidden", False):
+                        result = m.get("dps_val", result)
+
+                step = cond.get("step", step)
+                redirect = cond.get("value_redirect", redirect)
+                target_range = cond.get("target_range", target_range)
+
+            if redirect:
+                _LOGGER.debug("Redirecting %s to %s", self.name, redirect)
+                r_dps = self._entity.find_dps(redirect)
+                if r_dps:
+                    return r_dps.get_values_to_set(device, value)
+
+            if scale != 1 and isinstance(result, Number):
+                _LOGGER.debug("Scaling %s by %s", result, scale)
+                result = result * scale
+                remap = self._find_map_for_value(result, device)
+                if (
+                    remap
+                    and "dps_val" in remap
+                    and "dps_val" not in mapping
+                    and not remap.get("hidden", False)
+                ):
+                    result = remap["dps_val"]
+                replaced = True
+
+            if target_range and isinstance(result, Number):
+                r = self._config.get("range")
+                if r and "max" in r and "max" in target_range:
+                    from_min = target_range.get("min", 0)
+                    from_max = target_range["max"]
+                    to_min = r.get("min", 0)
+                    to_max = r["max"]
+                    result = to_min + (
+                        (result - from_min) * (to_max - to_min) / (from_max - from_min)
+                    )
+                    replaced = True
+
+            if invert:
+                r = self._config.get("range")
+                if r and "min" in r and "max" in r:
+                    result = -1 * result + r["min"] + r["max"]
+                    replaced = True
+
+            if step and isinstance(result, Number):
+                _LOGGER.debug("Stepping %s to %s", result, step)
+                result = step * round(float(result) / step)
+                remap = self._find_map_for_value(result, device)
+                if (
+                    remap
+                    and "dps_val" in remap
+                    and "dps_val" not in mapping
+                    and not remap.get("hidden", False)
+                ):
+                    result = remap["dps_val"]
+                replaced = True
+
+            if replaced:
+                _LOGGER.debug(
+                    "%s: Mapped dps %s to %s from %s",
+                    self._entity._device.name,
+                    self.id,
+                    result,
+                    value,
+                )
+
+        r = self.range(device, scaled=False)
+        if r and isinstance(result, Number):
+            mn = r[0]
+            mx = r[1]
+            if round(result) < mn or round(result) > mx:
+                # Output scaled values in the error message
+                r = self.range(device, scaled=True)
+                mn = r[0]
+                mx = r[1]
+                raise ValueError(f"{self.name} ({value}) must be between {mn} and {mx}")
+        if mask and isinstance(result, bool):
+            result = int(result)
+
+        if mask and isinstance(result, Number):
+            # mask is in hex, 2 digits/characters per byte
+            hex_mask = self._config.get("mask")
+            length = int(len(hex_mask) / 2)
+            # Convert to int
+            endianness = self.endianness
+            mask_scale = mask & (1 + ~mask)
+            current_value = int.from_bytes(self.decoded_value(device), endianness)
+            result = (current_value & ~mask) | (mask & int(result * mask_scale))
+            result = self.encode_value(result.to_bytes(length, endianness))
+
+        dps_map[self.id] = self._correct_type(result)
+        return dps_map
+
+    def icon_rule(self, device):
+        mapping = self._find_map_for_dps(device.get_property(self.id), device)
+        icon = None
+        priority = 100
+        if mapping:
+            icon = mapping.get("icon", icon)
+            priority = mapping.get("icon_priority", 10 if icon else 100)
+            cond = self._active_condition(mapping, device)
+            if cond and cond.get("icon_priority", 10) < priority:
+                icon = cond.get("icon", icon)
+                priority = cond.get("icon_priority", 10 if icon else 100)
+
+        return {"priority": priority, "icon": icon}
+
+
+def available_configs():
+    """List the available config files."""
+    _CONFIG_DIR = dirname(config_dir.__file__)
+
+    for path, dirs, files in walk(_CONFIG_DIR):
+        for basename in sorted(files):
+            if fnmatch(basename, "*.yaml"):
+                yield basename
+
+
+def possible_matches(dps, product_ids=None):
+    """Return possible matching configs for a given set of
+    dps values and product_ids."""
+    for cfg in available_configs():
+        parsed = TuyaDeviceConfig(cfg)
+        try:
+            if parsed.matches(dps, product_ids):
+                yield parsed
+        except TypeError:
+            _LOGGER.error("Parse error in %s", cfg)
+
+
+def get_config(conf_type):
+    """
+    Return a config to use with config_type.
+    """
+    _CONFIG_DIR = dirname(config_dir.__file__)
+    fname = conf_type + ".yaml"
+    fpath = join(_CONFIG_DIR, fname)
+    if exists(fpath):
+        return TuyaDeviceConfig(fname)
+    else:
+        return config_for_legacy_use(conf_type)
+
+
+def config_for_legacy_use(conf_type):
+    """
+    Return a config to use with config_type for legacy transition.
+    Note: as there are two variants for Kogan Socket, this is not guaranteed
+    to be the correct config for the device, so only use it for looking up
+    the legacy class during the transition period.
+    """
+    for cfg in available_configs():
+        parsed = TuyaDeviceConfig(cfg)
+        if parsed.legacy_type == conf_type:
+            return parsed
+
+    return None

+ 1680 - 1680
tests/const.py

@@ -1,1680 +1,1680 @@
-GPPH_HEATER_PAYLOAD = {
-    "1": False,
-    "2": 25,
-    "3": 17,
-    "4": "C",
-    "6": True,
-    "12": 0,
-    "101": "5",
-    "102": 0,
-    "103": False,
-    "104": True,
-    "105": "auto",
-    "106": 20,
-}
-
-GPCV_HEATER_PAYLOAD = {
-    "1": True,
-    "2": True,
-    "3": 30,
-    "4": 25,
-    "5": 0,
-    "6": 0,
-    "7": "Low",
-}
-
-EUROM_600_HEATER_PAYLOAD = {"1": True, "2": 15, "5": 18, "6": 0}
-EUROM_600v2_HEATER_PAYLOAD = {"1": True, "2": 15, "5": 18, "7": 0}
-
-EUROM_601_HEATER_PAYLOAD = {"1": True, "2": 21, "3": 20, "6": False, "13": 0}
-
-EUROM_WALLDESIGNHEAT2000_HEATER_PAYLOAD = {
-    "1": True,
-    "2": 21,
-    "3": 19,
-    "4": "off",
-    "7": False,
-}
-
-EUROM_SANIWALLHEAT2000_HEATER_PAYLOAD = {
-    "1": True,
-    "2": 21,
-    "3": 19,
-    "4": "off",
-    "7": False,
-}
-
-GECO_HEATER_PAYLOAD = {"1": True, "2": True, "3": 30, "4": 25, "5": 0, "6": 0}
-
-JJPRO_JPD01_PAYLOAD = {
-    "1": True,
-    "2": "0",
-    "4": 50,
-    "5": True,
-    "6": "1",
-    "11": 0,
-    "12": 0,
-    "101": False,
-    "102": False,
-    "103": 20,
-    "104": 62,
-    "105": False,
-}
-
-KOGAN_HEATER_PAYLOAD = {"2": 30, "3": 25, "4": "Low", "6": True, "7": True, "8": 0}
-
-KOGAN_KAWFHTP_HEATER_PAYLOAD = {
-    "1": True,
-    "2": True,
-    "3": 30,
-    "4": 25,
-    "5": 0,
-    "7": "Low",
-}
-
-KOGAN_KASHMFP20BA_HEATER_PAYLOAD = {
-    "1": True,
-    "2": "high",
-    "3": 27,
-    "4": 26,
-    "5": "orange",
-    "6": "white",
-}
-
-DEHUMIDIFIER_PAYLOAD = {
-    "1": False,
-    "2": "0",
-    "4": 30,
-    "5": False,
-    "6": "1",
-    "7": False,
-    "11": 0,
-    "12": "0",
-    "101": False,
-    "102": False,
-    "103": 20,
-    "104": 78,
-    "105": False,
-}
-
-FAN_PAYLOAD = {"1": False, "2": "12", "3": "normal", "8": True, "11": "0", "101": False}
-
-KOGAN_SOCKET_PAYLOAD = {
-    "1": True,
-    "2": 0,
-    "4": 200,
-    "5": 460,
-    "6": 2300,
-}
-
-KOGAN_SOCKET_PAYLOAD2 = {
-    "1": True,
-    "9": 0,
-    "18": 200,
-    "19": 460,
-    "20": 2300,
-}
-
-SMARTSWITCH_ENERGY_PAYLOAD = {
-    "1": True,
-    "9": 0,
-    "17": 100,
-    "18": 2368,
-    "19": 4866,
-    "20": 2148,
-    "21": 1,
-    "22": 628,
-    "23": 30636,
-    "24": 17426,
-    "25": 2400,
-    "26": 0,
-    "38": "memory",
-    "41": "",
-    "42": "",
-    "46": False,
-}
-
-KOGAN_SOCKET_CLEAR_PAYLOAD = {
-    "2": None,
-    "4": None,
-    "5": None,
-    "6": None,
-    "9": None,
-    "18": None,
-    "19": None,
-    "20": None,
-}
-
-GSH_HEATER_PAYLOAD = {
-    "1": True,
-    "2": 22,
-    "3": 24,
-    "4": "low",
-    "12": 0,
-}
-
-GARDENPAC_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "102": 28,
-    "103": True,
-    "104": 100,
-    "105": "warm",
-    "106": 30,
-    "107": 18,
-    "108": 45,
-    "115": 0,
-    "116": 0,
-    "117": True,
-}
-
-IPS_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": "silence",
-    "102": 10,
-    "103": True,
-    "104": 100,
-    "105": "warm",
-    "106": 30,
-    "107": 18,
-    "108": 40,
-    "115": 0,
-    "116": 0,
-}
-
-MADIMACK_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "102": 9,
-    "103": True,
-    "104": 0,
-    "105": "warm",
-    "106": 30,
-    "107": 18,
-    "108": 45,
-    "115": 4,
-    "116": 0,
-    "117": True,
-    "118": False,
-    "120": 8,
-    "122": 11,
-    "124": 9,
-    "125": 0,
-    "126": 0,
-    "127": 17,
-    "128": 480,
-    "129": 0,
-    "130": False,
-    "134": False,
-    "135": False,
-    "136": False,
-    "139": False,
-    "140": "LowSpeed",
-}
-
-MADIMACK_ELITEV3_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": "heating",
-    "4": 28,
-    "5": "power",
-    "6": "c",
-    "15": 0,
-    "20": 50,
-    "21": 40,
-    "22": 18,
-    "23": 45,
-    "24": 40,
-    "25": 33,
-    "26": 18,
-    "101": 0,
-    "102": 21,
-    "103": 23,
-    "104": 18,
-    "105": 18,
-    "106": 480,
-    "107": False,
-}
-
-PURLINE_M100_HEATER_PAYLOAD = {
-    "1": True,
-    "2": 23,
-    "3": 23,
-    "5": "off",
-    "10": True,
-    "11": 0,
-    "12": 0,
-    "101": False,
-    "102": False,
-}
-
-REMORA_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "heat", "9": 0}
-BWT_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "auto", "9": 0}
-
-EANONS_HUMIDIFIER_PAYLOAD = {
-    "2": "middle",
-    "3": "cancel",
-    "4": 0,
-    "9": 0,
-    "10": True,
-    "12": "humidity",
-    "15": 65,
-    "16": 65,
-    "22": True,
-}
-
-INKBIRD_ITC306A_THERMOSTAT_PAYLOAD = {
-    "12": 0,
-    "101": "C",
-    "102": 0,
-    "103": "on",
-    "104": 257,
-    "106": 252,
-    "108": 6,
-    "109": 1000,
-    "110": 0,
-    "111": False,
-    "112": False,
-    "113": False,
-    "114": 260,
-    "115": True,
-    "116": 783,
-    "117": False,
-    "118": False,
-    "119": False,
-    "120": False,
-}
-
-INKBIRD_ITC308_THERMOSTAT_PAYLOAD = {
-    "12": 0,
-    "101": "C",
-    "102": 0,
-    "104": 136,
-    "106": 15,
-    "108": 3,
-    "109": 370,
-    "110": 10,
-    "111": False,
-    "112": False,
-    "113": False,
-    "115": "1",
-    "116": 565,
-    "117": 10,
-    "118": 5,
-}
-
-ANKO_FAN_PAYLOAD = {
-    "1": True,
-    "2": "normal",
-    "3": "1",
-    "4": "off",
-    "6": "0",
-}
-
-DETA_FAN_PAYLOAD = {
-    "1": True,
-    "3": "1",
-    "9": False,
-    "101": True,
-    "102": "0",
-    "103": "0",
-}
-
-ELECTRIQ_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": "auto",
-    "3": 60,
-    "4": 45,
-    "7": False,
-    "10": False,
-    "102": "90",
-    "103": 20,
-    "104": False,
-}
-
-ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": "high",
-    "3": 39,
-    "4": 45,
-    "5": False,
-    "10": False,
-    "101": False,
-    "102": "0_90",
-    "103": 30,
-}
-
-ELECTRIQ_CD12PW_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": "high",
-    "3": 39,
-    "4": 45,
-    "101": False,
-    "103": 30,
-}
-
-ELECTRIQ_CD12PWV2_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": 45,
-    "5": "Smart",
-    "6": 39,
-    "19": 0,
-    "101": True,
-    "104": False,
-}
-
-ELECTRIQ_DESD9LW_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": 50,
-    "4": "Low",
-    "5": "Dehumidity",
-    "6": 55,
-    "7": 18,
-    "10": False,
-    "12": False,
-    "15": False,
-    "101": 20,
-}
-
-POOLEX_SILVERLINE_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "Heat", "13": 0}
-POOLEX_VERTIGO_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "heat", "9": 0}
-POOLEX_QLINE_HEATPUMP_PAYLOAD = {"1": True, "2": "heating", "4": 30, "15": 0, "16": 28}
-
-ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": 20,
-    "3": 18,
-    "4": "auto",
-    "5": "1",
-    "8": False,
-    "12": False,
-    "101": True,
-    "102": False,
-    "103": False,
-    "104": True,
-    "106": False,
-    "107": False,
-    "108": 0,
-    "109": 0,
-    "110": 0,
-}
-
-KOGAN_DEHUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "2": "low",
-    "3": 70,
-    "8": False,
-    "11": 0,
-    "12": 0,
-    "13": 0,
-    "101": 50,
-}
-
-HELLNAR_HEATPUMP_PAYLOAD = {
-    "1": False,
-    "2": 260,
-    "3": 26,
-    "4": "cold",
-    "5": "low",
-    "18": 0,
-    "20": 0,
-    "105": "off",
-    "110": 131644,
-    "113": "0",
-    "114": "0",
-    "119": "0",
-    "120": "off",
-    "123": "0010",
-    "126": "0",
-    "127": "0",
-    "128": "0",
-    "129": "1",
-    "130": 26,
-    "131": False,
-    "132": False,
-    "133": "0",
-    "134": '{"t":1624086077,"s":false,"clr"true}',
-}
-
-TADIRAN_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": 25,
-    "3": 250,
-    "4": "cooling",
-    "5": "low",
-    "101": 0,
-    "102": 260,
-    "103": 225,
-    "104": "low",
-    "105": "stop",
-    "106": -300,
-    "107": False,
-    "108": False,
-}
-
-BECA_BHP6000_PAYLOAD = {
-    "1": True,
-    "2": 77,
-    "3": 87,
-    "4": "3",
-    "5": "3",
-    "6": False,
-    "7": False,
-}
-
-BECA_BHT6000_PAYLOAD = {
-    "1": False,
-    "2": 40,
-    "3": 42,
-    "4": "0",
-    "5": False,
-    "6": False,
-    "102": 0,
-    "103": "1",
-    "104": True,
-}
-
-BECA_BHT002_PAYLOAD = {
-    "1": False,
-    "2": 40,
-    "3": 42,
-    "4": "0",
-    "5": False,
-    "6": False,
-    "102": 0,
-    "104": True,
-}
-
-MOES_BHT002_PAYLOAD = {
-    "1": False,
-    "2": 40,
-    "3": 42,
-    "4": "0",
-    "5": False,
-    "6": False,
-    "104": True,
-}
-
-BEOK_TR9B_PAYLOAD = {
-    "1": True,
-    "2": "manual",
-    "10": True,
-    "16": 590,
-    "19": 990,
-    "23": "f",
-    "24": 666,
-    "26": 410,
-    "31": "5_2",
-    "36": "close",
-    "40": False,
-    "45": 0,
-    "101": 1313,
-    "102": 10,
-}
-
-BECA_BAC002_PAYLOAD = {
-    "1": True,
-    "2": 39,
-    "3": 45,
-    "4": "1",
-    "5": False,
-    "6": False,
-    "102": "1",
-    "103": "2",
-}
-
-LEXY_F501_PAYLOAD = {
-    "1": True,
-    "2": "forestwindhigh",
-    "4": "off",
-    "6": 0,
-    "9": False,
-    "16": False,
-    "17": False,
-    "102": 8,
-}
-
-TH213_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": 18,
-    "3": 20,
-    "4": 1,
-    "6": False,
-    "12": 0,
-    "101": 16,
-    "102": 2,
-    "103": 0,
-    "104": 2,
-    "105": True,
-    "107": False,
-    "108": False,
-    "110": 0,
-}
-
-TH213V2_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": 16,
-    "3": 21,
-    "4": "3",
-    "6": False,
-    "12": 0,
-    "101": 23,
-    "102": "2",
-    "103": 1,
-    "104": 1,
-    "105": False,
-    "116": "1",
-}
-
-WETAIR_WCH750_HEATER_PAYLOAD = {
-    "1": False,
-    "2": 17,
-    "4": "mod_free",
-    "11": "heating",
-    "19": "0h",
-    "20": 0,
-    "21": 0,
-    "101": "level1",
-}
-
-WETAIR_WAWH1210_HUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "5": True,
-    "8": True,
-    "13": 50,
-    "14": 57,
-    "22": 0,
-    "24": "AUTO",
-    "25": True,
-    "29": False,
-    "101": "Have_water",
-}
-
-SASWELL_T29UTK_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": 240,
-    "3": 241,
-    "4": "cold",
-    "5": "auto",
-    "19": "C",
-    "101": False,
-    "102": False,
-    "103": "cold",
-    "112": "3",
-    "113": 0,
-    "114": 24,
-    "115": 24,
-    "116": 75,
-    "117": 81,
-}
-
-SASWELL_C16_THERMOSTAT_PAYLOAD = {
-    "2": 220,
-    "3": "Smart",
-    "4": 0,
-    "5": 217,
-    "6": 350,
-    "7": False,
-    "8": 241,
-    "9": False,
-    "10": True,
-    "11": False,
-    "12": "7",
-    "14": "0",
-    "15": 0,
-    "17": 0,
-    "21": False,
-    "22": 1500,
-    "23": 12,
-    "24": "Standby",
-    "26": 50,
-}
-
-FERSK_VIND2_PAYLOAD = {
-    "1": True,
-    "2": 22,
-    "3": 23,
-    "4": "COOL",
-    "5": 1,
-    "19": "C",
-    "101": False,
-    "102": False,
-    "103": 0,
-    "104": False,
-    "105": 0,
-    "106": 0,
-    "109": False,
-    "110": 0,
-}
-
-KOGAN_GLASS_1_7L_KETTLE_PAYLOAD = {
-    "1": False,
-    "5": 99,
-    #    "102": "90",
-}
-
-RENPHO_PURIFIER_PAYLOAD = {
-    "1": True,
-    "4": "low",
-    "7": False,
-    "8": False,
-    "19": "0",
-    "22": "0",
-    "101": False,
-    "102": 0,
-    "103": 0,
-    "104": 0,
-    "105": 0,
-}
-
-ARLEC_FAN_PAYLOAD = {
-    "1": True,
-    "3": 1,
-    "4": "forward",
-    "102": "normal",
-    "103": "off",
-}
-
-ARLEC_FAN_LIGHT_PAYLOAD = {
-    "1": True,
-    "3": "6",
-    "4": "forward",
-    "9": False,
-    "10": 100,
-    "11": 100,
-    "102": "normal",
-    "103": "off",
-}
-
-CARSON_CB_PAYLOAD = {
-    "1": True,
-    "2": 20,
-    "3": 23,
-    "4": "COOL",
-    "5": 1,
-    "19": "C",
-    "102": False,
-    "103": 0,
-    "104": False,
-    "105": 0,
-    "106": 0,
-    "110": 0,
-}
-
-KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD = {
-    "1": True,
-    "2": 19,
-    "3": 18,
-    "4": "COOL",
-    "5": "1",
-    "19": "C",
-    "105": 0,
-    "106": 0,
-    "107": False,
-}
-
-GRIDCONNECT_2SOCKET_PAYLOAD = {
-    "1": True,
-    "2": True,
-    "9": 0,
-    "10": 0,
-    "17": 0,
-    "18": 500,
-    "19": 1200,
-    "20": 240,
-    "21": 0,
-    "22": 0,
-    "23": 0,
-    "24": 0,
-    "25": 0,
-    "38": "0",
-    "40": False,
-    "101": True,
-}
-
-EBERG_QUBO_Q40HD_PAYLOAD = {
-    "1": True,
-    "2": 22,
-    "3": 20,
-    "4": "hot",
-    "5": "middle",
-    "19": "c",
-    "22": 0,
-    "25": False,
-    "30": False,
-    "101": "heat_s",
-}
-
-EBERG_COOLY_C35HD_PAYLOAD = {
-    "1": True,
-    "4": 0,
-    "5": "4",
-    "6": 25,
-    "8": "1",
-    "10": False,
-    "13": 0,
-    "14": 0,
-    "15": 0,
-    "16": False,
-    "17": False,
-    "18": 78,
-    "19": False,
-}
-
-STIRLING_FS1_FAN_PAYLOAD = {
-    "1": True,
-    "2": "normal",
-    "3": 9,
-    "5": False,
-    "22": "cancel",
-}
-
-QOTO_SPRINKLER_PAYLOAD = {
-    "102": 100,
-    "103": 100,
-    "104": 10036,
-    "105": 10800,
-    "108": 0,
-}
-
-MINCO_MH1823D_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": "program",
-    "3": "stop",
-    "5": False,
-    "9": True,
-    "12": False,
-    "18": "out",
-    "19": "c",
-    "22": 18,
-    "23": 64,
-    "32": 1,
-    "33": 205,
-    "35": 0,
-    "37": 689,
-    "39": "7",
-    "45": 0,
-    "101": 200,
-    "102": 680,
-    "103": 0,
-    "104": 2,
-    "105": "no_power",
-    "106": 35,
-    "107": 95,
-}
-
-SIMPLE_GARAGE_DOOR_PAYLOAD = {
-    "1": True,
-    "101": False,
-}
-
-NEDIS_HTPL20F_PAYLOAD = {
-    "1": True,
-    "2": 25,
-    "3": 25,
-    "4": "1",
-    "7": False,
-    "11": "0",
-    "13": 0,
-    "101": False,
-}
-
-ASPEN_ASP200_FAN_PAYLOAD = {
-    "1": True,
-    "2": "in",
-    "3": 1,
-    "8": 0,
-    "18": 20,
-    "19": 25,
-    "101": True,
-    "102": 3,
-}
-
-TMWF02_FAN_PAYLOAD = {
-    "1": True,
-    "2": 0,
-    "3": "level_2",
-    "4": 40,
-}
-
-TIMED_SOCKET_PAYLOAD = {
-    "1": True,
-    "11": 0,
-}
-
-TIMED_SOCKETV2_PAYLOAD = {
-    "1": True,
-    "9": 0,
-}
-
-DIGOO_DGSP202_SOCKET_PAYLOAD = {
-    "1": True,
-    "2": True,
-    "9": 0,
-    "10": 0,
-    "18": 500,
-    "19": 1200,
-    "20": 240,
-}
-
-DIGOO_DGSP01_SOCKET_PAYLOAD = {
-    "1": True,
-    "27": True,
-    "28": "colour",
-    "29": 76,
-    "31": "1c0d00001b640b",
-    "32": "3855b40168ffff",
-    "33": "ffff500100ff00",
-    "34": "ffff8003ff000000ff000000ff000000000000000000",
-    "35": "ffff5001ff0000",
-    "36": "ffff0505ff000000ff00ffff00ff00ff0000ff000000",
-}
-
-WOOX_R4028_SOCKET_PAYLOAD = {
-    "1": True,
-    "2": True,
-    "3": True,
-    "7": True,
-    "101": 0,
-    "102": 0,
-    "103": 0,
-    "105": 0,
-}
-
-OWON_PCT513_THERMOSTAT_PAYLOAD = {
-    "2": "cool",
-    "16": 2150,
-    "17": 71,
-    "23": "c",
-    "24": 2950,
-    "29": 85,
-    "34": 52,
-    "45": 0,
-    "107": "0",
-    "108": 2150,
-    "109": 1650,
-    "110": 71,
-    "111": 62,
-    "115": "auto",
-    "116": "1",
-    "119": True,
-    "120": "permhold",
-    "123": 25,
-    "129": "coolfanon",
-}
-
-HYSEN_HY08WE2_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": 50,
-    "3": 170,
-    "4": "Manual",
-    "6": False,
-    "12": 0,
-    "101": False,
-    "102": False,
-    "103": 170,
-    "104": 4,
-    "105": 15,
-    "106": True,
-    "107": True,
-    "108": True,
-    "109": -10,
-    "110": 10,
-    "111": 2,
-    "112": 35,
-    "113": 5,
-    "114": 30,
-    "115": 5,
-    "116": "all",
-    "117": "keep",
-    "118": "2days",
-}
-
-POIEMA_ONE_PURIFIER_PAYLOAD = {
-    "1": True,
-    "2": 12,
-    "3": "manual",
-    "4": "mid",
-    "7": False,
-    "11": False,
-    "18": "cancel",
-    "19": 0,
-}
-
-ECOSTRAD_IQCERAMIC_RADIATOR_PAYLOAD = {
-    "1": True,
-    "2": "hot",
-    "16": 180,
-    "24": 90,
-    "27": 0,
-    "40": False,
-    "104": "15",
-    "107": "1",
-    "108": "0",
-    "109": "0",
-}
-
-NASHONE_MTS700WB_THERMOSTAT_PAYLOAD = {
-    "1": True,
-    "2": "hot",
-    "3": "manual",
-    "16": 20,
-    "17": 68,
-    "23": "c",
-    "24": 19,
-    "27": 0,
-    "29": 66,
-    "39": False,
-    "41": "cancel",
-    "42": 0,
-}
-
-LEFANT_M213_VACUUM_PAYLOAD = {
-    "1": True,
-    "2": False,
-    "3": "standby",
-    "4": "forward",
-    "5": "0",
-    "6": 91,
-    "13": False,
-    "16": 0,
-    "17": 0,
-    "18": 0,
-    "101": "nar",
-    "102": -23,
-    "103": 27,
-    "104": 0,
-    #   "106": "ChargeStage:DETSWITCGH",
-    #    "108": "BatVol:13159",
-}
-
-KYVOL_E30_VACUUM_PAYLOAD = {
-    "1": True,
-    "2": False,
-    "3": "standby",
-    "4": "stop",
-    "5": "Charging_Base",
-    "6": 2,
-    "7": 20,
-    "8": 60,
-    "9": 20,
-    "10": False,
-    "11": False,
-    "12": False,
-    "13": False,

-    "14": "3",
-    "16": 0,
-    "17": 0,
-    "18": 0,
-    "101": "2",
-    "102": "900234",
-    "104": "standby",
-    "107": 1,
-}
-
-HIMOX_H06_PURIFIER_PAYLOAD = {
-    "1": True,
-    "4": "low",
-    "5": 50,
-    "8": True,
-    "11": False,
-    "18": "cancel",
-    "19": 0,
-    "22": "medium",
-    "101": "calcle",
-}
-
-HIMOX_H05_PURIFIER_PAYLOAD = {
-    "1": True,
-    "2": 21,
-    "4": "auto",
-    "5": 92,
-    "7": False,
-    "11": False,
-    "18": "cancel",
-    "21": "good",
-}
-
-VORK_VK6067_PURIFIER_PAYLOAD = {
-    "1": True,
-    "4": "auto",
-    "5": 80,
-    "8": True,
-    "11": False,
-    "18": "cancel",
-    "19": 0,
-    "21": "good",
-    "22": 0,
-}
-
-KOGAN_GARAGE_DOOR_PAYLOAD = {
-    "101": "fopen",
-    "102": "opening",
-    "104": 100,
-    "105": True,
-}
-
-MOES_RGB_SOCKET_PAYLOAD = {
-    "1": True,
-    "2": "colour",
-    "3": 255,
-    "4": 14,
-    "5": "ff99000024ffff",
-    "6": "bd76000168ffff",
-    "7": "ffff320100ff00",
-    "8": "ffff3203ff000000ff000000ff",
-    "9": "ffff3201ff0000",
-    "10": "ffff3205ff000000ff00ffff00ff00ff0000ff",
-    "101": True,
-    "102": 0,
-    "104": 0,
-    "105": 0,
-    "106": 2332,
-}
-
-LOGICOM_STRIPPY_PAYLOAD = {
-    "1": False,
-    "2": False,
-    "3": False,
-    "4": False,
-    "5": False,
-    "9": 0,
-    "10": 0,
-    "11": 0,
-    "12": 0,
-    "13": 0,
-}
-
-PARKSIDE_PLGS2012A1_PAYLOAD = {
-    "1": True,
-    "2": "test",
-    "3": 1000,
-    "4": 1320,
-    "5": 80,
-    "6": 25,
-    "7": "standard",
-    "8": False,
-    "9": True,
-    "10": 5,
-    "11": 0,
-    "101": 2500,
-    "102": 11,
-    "103": False,
-    "104": False,
-}
-
-SD123_PRESENCE_PAYLOAD = {
-    "1": "none",
-    "101": "0_meters",
-    "102": "6_meters",
-    "103": "case_0",
-    "104": "case_1",
-    "105": "not_reset",
-    "106": "normal",
-    "107": 1200,
-    "108": 1000,
-    "109": 1,
-    "110": 1,
-    "111": 10,
-    "112": 2,
-    "113": 0,
-    "114": True,
-}
-
-SIMPLE_BLINDS_PAYLOAD = {
-    "1": "stop",
-    "2": 0,
-    "5": False,
-    "7": "opening",
-}
-
-STARLIGHT_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": 260,
-    "3": 22,
-    "4": "hot",
-    "5": "auto",
-    "18": 0,
-    "20": 0,
-    "105": "off",
-    "110": 131644,
-    "113": "0",
-    "114": "0",
-    "119": "0",
-    "120": "off",
-    "123": "0018",
-    "126": "0",
-    "127": "0",
-    "128": "0",
-    "129": "1",
-    "130": 26,
-    "131": False,
-    "132": False,
-    "133": "0",
-    "134": '{"t":8601,"s":false,"clr":true}',
-}
-
-WILFA_HAZE_HUMIDIFIER_PAYLOAD = {
-    "1": True,
-    "5": False,
-    "8": False,
-    "10": 20,
-    "13": 70,
-    "14": 55,
-    "16": False,
-    "18": "c",
-    "19": "cancel",
-    "20": 0,
-    "22": 0,
-    "23": "level_3",
-    "24": "humidity",
-    "26": False,
-    "35": False,
-}
-
-WEAU_POOL_HEATPUMP_PAYLOAD = {
-    "1": True,
-    "2": 33,
-    "3": 195,
-    "4": "auto",
-    "6": 0,
-}
-
-WEAU_POOL_HEATPUMPV2_PAYLOAD = {
-    "1": True,
-    "2": "eheat",
-    "9": 15,
-    "10": 260,
-    "20": 0,
-    "101": 0,
-    "102": 40,
-    "103": 15,
-    "104": True,
-}
-
-SMARTPLUG_ENCODED_PAYLOAD = {
-    "1": True,
-    "11": 0,
-    "101": "QVA=",
-    "102": "QVA=",
-    "103": "QVA=",
-}
-
-DEVOLA_PATIO_HEATER_PAYLOAD = {
-    "1": True,
-    "2": 20,
-    "3": 15,
-    "4": "smart",
-    "5": "4",
-    "6": False,
-    "7": False,
-    "12": 0,
-    "14": "heating",
-    "19": "c",
-    "20": 68,
-    "21": 59,
-}
-
-QS_C01_CURTAIN_PAYLOAD = {
-    "1": "stop",
-    "2": 0,
-    "8": "forward",
-    "10": 20,
-}
-
-M027_CURTAIN_PAYLOAD = {
-    "1": "close",
-    "2": 0,
-    "4": "morning",
-    "7": "closing",
-    "10": 0,
-    "12": 0,
-    "101": False,
-}
-
-JIAHONG_ET72W_PAYLOAD = {
-    "101": True,
-    "102": 220,
-    "103": "Manual",
-    "104": 0,
-    "105": 205,
-    "106": 240,
-    "107": False,
-    "108": False,
-    "109": False,
-    "110": 2,
-    "111": "0",
-    "112": 0,
-    "113": 0,
-    "116": 500,
-    "117": 1234,
-    "118": True,
-    "121": 300,
-}
-
-BETTERLIFE_BL1500_PAYLOAD = {
-    "1": True,
-    "2": 20,
-    "4": "0",
-    "7": False,
-    "11": "0",
-    "12": 0,
-}
-
-EESEE_ADAM_PAYLOAD = {
-    "1": True,
-    "2": 50,
-    "4": "manual",
-    "5": "low",
-    "14": False,
-    "16": 72,
-    "17": "cancel",
-    "19": 0,
-}
-
-ALECOAIR_D14_PAYLOAD = {
-    "1": True,
-    "2": 50,
-    "4": "manual",
-    "5": "low",
-    "10": False,
-    "14": False,
-    "16": 72,
-    "17": "cancel",
-    "19": 0,
-}
-
-HYUNDAI_SAHARA_PAYLOAD = {
-    "1": True,
-    "2": 50,
-    "4": "high",
-    "6": 73,
-    "7": 25,
-    "14": False,
-    "16": False,
-    "19": 0,
-}
-
-RGBCW_LIGHTBULB_PAYLOAD = {
-    "20": True,
-    "21": "white",
-    "22": 1000,
-    "23": 500,
-    "24": "0000000003e8",
-    "25": "000e0d0000000000000000c80000",
-    "26": 0,
-}
-
-MOES_TEMP_HUMID_PAYLOAD = {
-    "1": True,
-    "2": False,
-    "3": True,
-    "4": "manual",
-    "6": 374,
-    "8": False,
-    "9": 0,
-    "11": False,
-    "12": 0,
-    "18": 0,
-    "20": 0,
-    "21": 0,
-    "22": 0,
-    "24": "",
-    "101": "",
-    "102": "",
-    "103": 0,
-    "104": 0,
-    "105": "off",
-    "106": "mix",
-}
-
-ORION_SMARTLOCK_PAYLOAD = {
-    "1": 0,
-    "2": 0,
-    "3": 0,
-    "4": 0,
-    "5": 0,
-    "8": 0,
-    "9": 0,
-    "10": False,
-    "12": 100,
-    "15": 0,
-    "16": False,
-}
-
-ELECTRIQ_AIRFLEX15W_PAYLOAD = {
-    "1": True,
-    "2": 16,
-    "3": 27,
-    "17": 90,
-    "20": 0,
-    "101": "1",
-    "103": False,
-    "104": "1",
-    "105": 0,
-    "106": False,
-    "109": False,
-    "112": 42,
-}
-
-PC321TY_POWERCLAMP_PAYLOAD = {
-    "101": 2284,
-    "102": 1073,
-    "103": 191,
-    "104": 78,
-    "106": 251,
-    "111": 2354,
-    "112": 748,
-    "113": 47,
-    "114": 100,
-    "116": 267,
-    "121": 2350,
-    "122": 753,
-    "123": 149,
-    "124": 84,
-    "126": 517,
-    "131": 1036,
-    "132": 2574,
-    "133": 188,
-    "135": 50,
-    "136": 390,
-}
-
-ENERGY_POWERSTRIP_PAYLOAD = {
-    "1": False,
-    "2": False,
-    "3": False,
-    "4": False,
-    "102": 0,
-    "103": 0,
-    "104": 2240,
-    "105": 1,
-    "106": 1709,
-    "107": 34620,
-    "108": 101000,
-    "109": 205,
-}
-
-COMPTEUR_SMARTMETER_PAYLOAD = {
-    "17": 12345,
-    "18": 2000,
-    "19": 4400,
-    "20": 2200,
-    "21": 0,
-    "22": 0,
-    "23": 0,
-    "24": 0,
-    "25": 0,
-    "26": 0,
-}
-
-BECOOL_HEATPUMP_PAYLOAD = {
-    "1": False,
-    "4": 0,
-    "5": "4",
-    "6": 24,
-    "8": "0",
-    "10": False,
-    "13": 0,
-    "14": 0,
-    "15": 0,
-    "16": True,
-    "17": False,
-    "19": False,
-}
-
-ESSENTIALS_PURIFIER_PAYLOAD = {
-    "1": True,
-    "2": 12,
-    "3": "auto",
-    "5": 50,
-    "7": False,
-    "9": False,
-    "11": False,
-    "18": "cancel",
-    "19": 0,
-    "21": "good",
-    "101": "Standard",
-}
-
-AVATTO_BLINDS_PAYLOAD = {
-    "1": "close",
-    "2": 0,
-    "3": 0,
-    "5": False,
-    "7": "closing",
-    "8": "cancel",
-    "9": 0,
-    "11": 0,
-}
-
-AVATTO_CURTAIN_PAYLOAD = {
-    "1": "stop",
-    "101": True,
-}
-
-ORION_SIREN_PAYLOAD = {
-    "1": "normal",
-    "5": "middle",
-    "6": True,
-    "7": 10,
-    "15": 0,
-    "20": True,
-}
-
-INKBIRD_SOUSVIDE_PAYLOAD = {
-    "101": False,
-    "102": "stop",
-    "103": 0,
-    "104": 297,
-    "105": 0,
-    "106": 0,
-    "107": 3,
-    "108": True,
-    "109": 0,
-    "110": 0,
-}
-
-HYDROTHERM_DYNAMICX8_PAYLOAD = {
-    "1": True,
-    "2": 65,
-    "3": 60,
-    "4": "STANDARD",
-    "21": 0,
-}
-
-TREATLIFE_DS02F_PAYLOAD = {
-    "1": True,
-    "2": 0,
-    "3": "level_2",
-}
-
-MOTION_LIGHT_PAYLOAD = {
-    "101": "mode_auto",
-    "102": False,
-    "103": 0,
-    "104": 249,
-    "105": 374,
-    "106": False,
-}
-
-BLITZWOLF_BWSH2_PAYLOAD = {
-    "1": True,
-    "3": "grade1",
-    "6": "close",
-    "19": "cancel",
-}
-
-BCOM_CAMERA_PAYLOAD = {
-    "101": True,
-    "103": False,
-    "104": False,
-    "106": "1",
-    "108": "0",
-    "109": "64GB",
-    "110": 1,
-    "111": False,
-    "115": "",
-    "117": 0,
-    "136": "",
-    "150": True,
-    "151": "1",
-    "162": False,
-    "231": "",
-    "232": False,
-}
-
-GX_AROMA_PAYLOAD = {
-    "1": True,
-    "2": "high",
-    "3": "cancel",
-    "4": 0,
-    "5": True,
-    "6": "colour",
-    "8": "b9fff500ab46ff",
-    "9": 0,
-}
-
-MOEBOT_PAYLOAD = {
-    "6": 41,
-    "101": "MOWING",
-    "102": 0,
-    "103": "MOWER_LEAN",
-    "104": True,
-    "105": 8,
-    "106": 1343,
-    "114": "AutoMode",
-}
-
-TOMPD63LW_SOCKET_PAYLOAD = {
-    "1": 139470,
-    "6": "CPQAFEkAAuk=",
-    "9": 0,
-    "11": False,
-    "12": False,
-    "13": 0,
-    "16": True,
-    "19": "FSE-F723C46A04FC6C",
-    # "101": 275,
-    # "102": 170,
-    # "103": 40,
-    # "104": 30,
-    # "105": False,
-    # "106": False,
-}
-
-GOLDAIR_GPDH340_PAYLOAD = {
-    "1": True,
-    "2": "2",
-    "4": 60,
-    "6": "2",
-    "11": 0,
-    "103": 20,
-    "104": 72,
-    "105": 40,
-    "106": False,
-    "107": True,
-    "108": False,
-    "109": False,
-}
-
-THERMEX_IF50V_PAYLOAD = {
-    "101": False,
-    "102": 37,
-    "104": 65,
-    "105": "2",
-    "106": 0,
-}
-
-ZXG30_ALARM_PAYLOAD = {
-    "1": "home",
-    "2": 0,
-    "3": 3,
-    "4": True,
-    "9": False,
-    "10": False,
-    "15": True,
-    "16": 100,
-    "17": True,
-    "20": False,
-    "21": False,
-    "22": 1,
-    "23": "2",
-    "24": "Normal",
-    "27": True,
-    "28": 10,
-    "29": True,
-    "32": "normal",
-    "34": False,
-    "35": False,
-    "36": "3",
-    "37": "0",
-    "39": "0",
-    "40": "1",
-}
-
-IR_REMOTE_SENSORS_PAYLOAD = {
-    "101": 200,
-    "102": 80,
-}
-
-LORATAP_CURTAINSWITCH_PAYLOAD = {
-    "1": "3",
-}
-
-BLE_WATERVALVE_PAYLOAD = {
-    "1": True,
-    "4": 0,
-    "7": 50,
-    "9": 3600,
-    "10": "cancel",
-    "12": "unknown",
-    "15": 60,
-}
-
-AM25_ROLLERBLIND_PAYLOAD = {
-    "1": "stop",
-    "2": 0,
-    "104": True,
-    "105": True,
-    "109": 4,
-}
-
-DUUX_BLIZZARD_PAYLOAD = {
-    "1": False,
-    "2": "fan",
-    "3": "high",
-    "4": 0,
-    "6": False,
-    "7": False,
-    "8": 22,
-    "9": 0,
-    "11": 72,
-    "12": True,
-    "13": False,
-    "14": False,
-    "15": 0,
-}
-
-BLE_SMARTPLANT_PAYLOAD = {
-    "3": 50,
-    "5": 25,
-    "9": "c",
-    "14": "Low",
-    "15": 20,
-}
-
-GOLDAIR_PORTABLE_AIR_CONDITIONER_PAYLOAD = {
-    "1": True,
-    "2": 22,
-    "3": 30,
-    "4": "cold",
-    "5": "low",
-    "11": False,
-    "15": "off",
-    "20": 0,
-    "103": False,
-    "104": 0,
-    "105": 0,
-    "107": 72,
-    "108": 80,
-    "109": 26,
-    "110": False,
-}
+GPPH_HEATER_PAYLOAD = {
+    "1": False,
+    "2": 25,
+    "3": 17,
+    "4": "C",
+    "6": True,
+    "12": 0,
+    "101": "5",
+    "102": 0,
+    "103": False,
+    "104": True,
+    "105": "auto",
+    "106": 20,
+}
+
+GPCV_HEATER_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "3": 30,
+    "4": 25,
+    "5": 0,
+    "6": 0,
+    "7": "Low",
+}
+
+EUROM_600_HEATER_PAYLOAD = {"1": True, "2": 15, "5": 18, "6": 0}
+EUROM_600v2_HEATER_PAYLOAD = {"1": True, "2": 15, "5": 18, "7": 0}
+
+EUROM_601_HEATER_PAYLOAD = {"1": True, "2": 21, "3": 20, "6": False, "13": 0}
+
+EUROM_WALLDESIGNHEAT2000_HEATER_PAYLOAD = {
+    "1": True,
+    "2": 21,
+    "3": 19,
+    "4": "off",
+    "7": False,
+}
+
+EUROM_SANIWALLHEAT2000_HEATER_PAYLOAD = {
+    "1": True,
+    "2": 21,
+    "3": 19,
+    "4": "off",
+    "7": False,
+}
+
+GECO_HEATER_PAYLOAD = {"1": True, "2": True, "3": 30, "4": 25, "5": 0, "6": 0}
+
+JJPRO_JPD01_PAYLOAD = {
+    "1": True,
+    "2": "0",
+    "4": 50,
+    "5": True,
+    "6": "1",
+    "11": 0,
+    "12": 0,
+    "101": False,
+    "102": False,
+    "103": 20,
+    "104": 62,
+    "105": False,
+}
+
+KOGAN_HEATER_PAYLOAD = {"2": 30, "3": 25, "4": "Low", "6": True, "7": True, "8": 0}
+
+KOGAN_KAWFHTP_HEATER_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "3": 30,
+    "4": 25,
+    "5": 0,
+    "7": "Low",
+}
+
+KOGAN_KASHMFP20BA_HEATER_PAYLOAD = {
+    "1": True,
+    "2": "high",
+    "3": 27,
+    "4": 26,
+    "5": "orange",
+    "6": "white",
+}
+
+DEHUMIDIFIER_PAYLOAD = {
+    "1": False,
+    "2": "0",
+    "4": 30,
+    "5": False,
+    "6": "1",
+    "7": False,
+    "11": 0,
+    "12": "0",
+    "101": False,
+    "102": False,
+    "103": 20,
+    "104": 78,
+    "105": False,
+}
+
+FAN_PAYLOAD = {"1": False, "2": "12", "3": "normal", "8": True, "11": "0", "101": False}
+
+KOGAN_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": 0,
+    "4": 200,
+    "5": 460,
+    "6": 2300,
+}
+
+KOGAN_SOCKET_PAYLOAD2 = {
+    "1": True,
+    "9": 0,
+    "18": 200,
+    "19": 460,
+    "20": 2300,
+}
+
+SMARTSWITCH_ENERGY_PAYLOAD = {
+    "1": True,
+    "9": 0,
+    "17": 100,
+    "18": 2368,
+    "19": 4866,
+    "20": 2148,
+    "21": 1,
+    "22": 628,
+    "23": 30636,
+    "24": 17426,
+    "25": 2400,
+    "26": 0,
+    "38": "memory",
+    "41": "",
+    "42": "",
+    "46": False,
+}
+
+KOGAN_SOCKET_CLEAR_PAYLOAD = {
+    "2": None,
+    "4": None,
+    "5": None,
+    "6": None,
+    "9": None,
+    "18": None,
+    "19": None,
+    "20": None,
+}
+
+GSH_HEATER_PAYLOAD = {
+    "1": True,
+    "2": 22,
+    "3": 24,
+    "4": "low",
+    "12": 0,
+}
+
+GARDENPAC_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "102": 28,
+    "103": True,
+    "104": 100,
+    "105": "warm",
+    "106": 30,
+    "107": 18,
+    "108": 45,
+    "115": 0,
+    "116": 0,
+    "117": True,
+}
+
+IPS_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": "silence",
+    "102": 10,
+    "103": True,
+    "104": 100,
+    "105": "warm",
+    "106": 30,
+    "107": 18,
+    "108": 40,
+    "115": 0,
+    "116": 0,
+}
+
+MADIMACK_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "102": 9,
+    "103": True,
+    "104": 0,
+    "105": "warm",
+    "106": 30,
+    "107": 18,
+    "108": 45,
+    "115": 4,
+    "116": 0,
+    "117": True,
+    "118": False,
+    "120": 8,
+    "122": 11,
+    "124": 9,
+    "125": 0,
+    "126": 0,
+    "127": 17,
+    "128": 480,
+    "129": 0,
+    "130": False,
+    "134": False,
+    "135": False,
+    "136": False,
+    "139": False,
+    "140": "LowSpeed",
+}
+
+MADIMACK_ELITEV3_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": "heating",
+    "4": 28,
+    "5": "power",
+    "6": "c",
+    "15": 0,
+    "20": 50,
+    "21": 40,
+    "22": 18,
+    "23": 45,
+    "24": 40,
+    "25": 33,
+    "26": 18,
+    "101": 0,
+    "102": 21,
+    "103": 23,
+    "104": 18,
+    "105": 18,
+    "106": 480,
+    "107": False,
+}
+
+PURLINE_M100_HEATER_PAYLOAD = {
+    "1": True,
+    "2": 23,
+    "3": 23,
+    "5": "off",
+    "10": True,
+    "11": 0,
+    "12": 0,
+    "101": False,
+    "102": False,
+}
+
+REMORA_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "heat", "9": 0}
+BWT_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "auto", "9": 0}
+
+EANONS_HUMIDIFIER_PAYLOAD = {
+    "2": "middle",
+    "3": "cancel",
+    "4": 0,
+    "9": 0,
+    "10": True,
+    "12": "humidity",
+    "15": 65,
+    "16": 65,
+    "22": True,
+}
+
+INKBIRD_ITC306A_THERMOSTAT_PAYLOAD = {
+    "12": 0,
+    "101": "C",
+    "102": 0,
+    "103": "on",
+    "104": 257,
+    "106": 252,
+    "108": 6,
+    "109": 1000,
+    "110": 0,
+    "111": False,
+    "112": False,
+    "113": False,
+    "114": 260,
+    "115": True,
+    "116": 783,
+    "117": False,
+    "118": False,
+    "119": False,
+    "120": False,
+}
+
+INKBIRD_ITC308_THERMOSTAT_PAYLOAD = {
+    "12": 0,
+    "101": "C",
+    "102": 0,
+    "104": 136,
+    "106": 15,
+    "108": 3,
+    "109": 370,
+    "110": 10,
+    "111": False,
+    "112": False,
+    "113": False,
+    "115": "1",
+    "116": 565,
+    "117": 10,
+    "118": 5,
+}
+
+ANKO_FAN_PAYLOAD = {
+    "1": True,
+    "2": "normal",
+    "3": "1",
+    "4": "off",
+    "6": "0",
+}
+
+DETA_FAN_PAYLOAD = {
+    "1": True,
+    "3": "1",
+    "9": False,
+    "101": True,
+    "102": "0",
+    "103": "0",
+}
+
+ELECTRIQ_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": "auto",
+    "3": 60,
+    "4": 45,
+    "7": False,
+    "10": False,
+    "102": "90",
+    "103": 20,
+    "104": False,
+}
+
+ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": "high",
+    "3": 39,
+    "4": 45,
+    "5": False,
+    "10": False,
+    "101": False,
+    "102": "0_90",
+    "103": 30,
+}
+
+ELECTRIQ_CD12PW_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": "high",
+    "3": 39,
+    "4": 45,
+    "101": False,
+    "103": 30,
+}
+
+ELECTRIQ_CD12PWV2_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": 45,
+    "5": "Smart",
+    "6": 39,
+    "19": 0,
+    "101": True,
+    "104": False,
+}
+
+ELECTRIQ_DESD9LW_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": 50,
+    "4": "Low",
+    "5": "Dehumidity",
+    "6": 55,
+    "7": 18,
+    "10": False,
+    "12": False,
+    "15": False,
+    "101": 20,
+}
+
+POOLEX_SILVERLINE_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "Heat", "13": 0}
+POOLEX_VERTIGO_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "heat", "9": 0}
+POOLEX_QLINE_HEATPUMP_PAYLOAD = {"1": True, "2": "heating", "4": 30, "15": 0, "16": 28}
+
+ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": 20,
+    "3": 18,
+    "4": "auto",
+    "5": "1",
+    "8": False,
+    "12": False,
+    "101": True,
+    "102": False,
+    "103": False,
+    "104": True,
+    "106": False,
+    "107": False,
+    "108": 0,
+    "109": 0,
+    "110": 0,
+}
+
+KOGAN_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": "low",
+    "3": 70,
+    "8": False,
+    "11": 0,
+    "12": 0,
+    "13": 0,
+    "101": 50,
+}
+
+HELLNAR_HEATPUMP_PAYLOAD = {
+    "1": False,
+    "2": 260,
+    "3": 26,
+    "4": "cold",
+    "5": "low",
+    "18": 0,
+    "20": 0,
+    "105": "off",
+    "110": 131644,
+    "113": "0",
+    "114": "0",
+    "119": "0",
+    "120": "off",
+    "123": "0010",
+    "126": "0",
+    "127": "0",
+    "128": "0",
+    "129": "1",
+    "130": 26,
+    "131": False,
+    "132": False,
+    "133": "0",
+    "134": '{"t":1624086077,"s":false,"clr"true}',
+}
+
+TADIRAN_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": 25,
+    "3": 250,
+    "4": "cooling",
+    "5": "low",
+    "101": 0,
+    "102": 260,
+    "103": 225,
+    "104": "low",
+    "105": "stop",
+    "106": -300,
+    "107": False,
+    "108": False,
+}
+
+BECA_BHP6000_PAYLOAD = {
+    "1": True,
+    "2": 77,
+    "3": 87,
+    "4": "3",
+    "5": "3",
+    "6": False,
+    "7": False,
+}
+
+BECA_BHT6000_PAYLOAD = {
+    "1": False,
+    "2": 40,
+    "3": 42,
+    "4": "0",
+    "5": False,
+    "6": False,
+    "102": 0,
+    "103": "1",
+    "104": True,
+}
+
+BECA_BHT002_PAYLOAD = {
+    "1": False,
+    "2": 40,
+    "3": 42,
+    "4": "0",
+    "5": False,
+    "6": False,
+    "102": 0,
+    "104": True,
+}
+
+MOES_BHT002_PAYLOAD = {
+    "1": False,
+    "2": 40,
+    "3": 42,
+    "4": "0",
+    "5": False,
+    "6": False,
+    "104": True,
+}
+
+BEOK_TR9B_PAYLOAD = {
+    "1": True,
+    "2": "manual",
+    "10": True,
+    "16": 590,
+    "19": 990,
+    "23": "f",
+    "24": 666,
+    "26": 410,
+    "31": "5_2",
+    "36": "close",
+    "40": False,
+    "45": 0,
+    "101": 1313,
+    "102": 10,
+}
+
+BECA_BAC002_PAYLOAD = {
+    "1": True,
+    "2": 39,
+    "3": 45,
+    "4": "1",
+    "5": False,
+    "6": False,
+    "102": "1",
+    "103": "2",
+}
+
+LEXY_F501_PAYLOAD = {
+    "1": True,
+    "2": "forestwindhigh",
+    "4": "off",
+    "6": 0,
+    "9": False,
+    "16": False,
+    "17": False,
+    "102": 8,
+}
+
+TH213_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": 18,
+    "3": 20,
+    "4": 1,
+    "6": False,
+    "12": 0,
+    "101": 16,
+    "102": 2,
+    "103": 0,
+    "104": 2,
+    "105": True,
+    "107": False,
+    "108": False,
+    "110": 0,
+}
+
+TH213V2_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": 16,
+    "3": 21,
+    "4": "3",
+    "6": False,
+    "12": 0,
+    "101": 23,
+    "102": "2",
+    "103": 1,
+    "104": 1,
+    "105": False,
+    "116": "1",
+}
+
+WETAIR_WCH750_HEATER_PAYLOAD = {
+    "1": False,
+    "2": 17,
+    "4": "mod_free",
+    "11": "heating",
+    "19": "0h",
+    "20": 0,
+    "21": 0,
+    "101": "level1",
+}
+
+WETAIR_WAWH1210_HUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "5": True,
+    "8": True,
+    "13": 50,
+    "14": 57,
+    "22": 0,
+    "24": "AUTO",
+    "25": True,
+    "29": False,
+    "101": "Have_water",
+}
+
+SASWELL_T29UTK_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": 240,
+    "3": 241,
+    "4": "cold",
+    "5": "auto",
+    "19": "C",
+    "101": False,
+    "102": False,
+    "103": "cold",
+    "112": "3",
+    "113": 0,
+    "114": 24,
+    "115": 24,
+    "116": 75,
+    "117": 81,
+}
+
+SASWELL_C16_THERMOSTAT_PAYLOAD = {
+    "2": 220,
+    "3": "Smart",
+    "4": 0,
+    "5": 217,
+    "6": 350,
+    "7": False,
+    "8": 241,
+    "9": False,
+    "10": True,
+    "11": False,
+    "12": "7",
+    "14": "0",
+    "15": 0,
+    "17": 0,
+    "21": False,
+    "22": 1500,
+    "23": 12,
+    "24": "Standby",
+    "26": 50,
+}
+
+FERSK_VIND2_PAYLOAD = {
+    "1": True,
+    "2": 22,
+    "3": 23,
+    "4": "COOL",
+    "5": 1,
+    "19": "C",
+    "101": False,
+    "102": False,
+    "103": 0,
+    "104": False,
+    "105": 0,
+    "106": 0,
+    "109": False,
+    "110": 0,
+}
+
+KOGAN_GLASS_1_7L_KETTLE_PAYLOAD = {
+    "1": False,
+    "5": 99,
+    #    "102": "90",
+}
+
+RENPHO_PURIFIER_PAYLOAD = {
+    "1": True,
+    "4": "low",
+    "7": False,
+    "8": False,
+    "19": "0",
+    "22": "0",
+    "101": False,
+    "102": 0,
+    "103": 0,
+    "104": 0,
+    "105": 0,
+}
+
+ARLEC_FAN_PAYLOAD = {
+    "1": True,
+    "3": 1,
+    "4": "forward",
+    "102": "normal",
+    "103": "off",
+}
+
+ARLEC_FAN_LIGHT_PAYLOAD = {
+    "1": True,
+    "3": "6",
+    "4": "forward",
+    "9": False,
+    "10": 100,
+    "11": 100,
+    "102": "normal",
+    "103": "off",
+}
+
+CARSON_CB_PAYLOAD = {
+    "1": True,
+    "2": 20,
+    "3": 23,
+    "4": "COOL",
+    "5": 1,
+    "19": "C",
+    "102": False,
+    "103": 0,
+    "104": False,
+    "105": 0,
+    "106": 0,
+    "110": 0,
+}
+
+KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD = {
+    "1": True,
+    "2": 19,
+    "3": 18,
+    "4": "COOL",
+    "5": "1",
+    "19": "C",
+    "105": 0,
+    "106": 0,
+    "107": False,
+}
+
+GRIDCONNECT_2SOCKET_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "9": 0,
+    "10": 0,
+    "17": 0,
+    "18": 500,
+    "19": 1200,
+    "20": 240,
+    "21": 0,
+    "22": 0,
+    "23": 0,
+    "24": 0,
+    "25": 0,
+    "38": "0",
+    "40": False,
+    "101": True,
+}
+
+EBERG_QUBO_Q40HD_PAYLOAD = {
+    "1": True,
+    "2": 22,
+    "3": 20,
+    "4": "hot",
+    "5": "middle",
+    "19": "c",
+    "22": 0,
+    "25": False,
+    "30": False,
+    "101": "heat_s",
+}
+
+EBERG_COOLY_C35HD_PAYLOAD = {
+    "1": True,
+    "4": 0,
+    "5": "4",
+    "6": 25,
+    "8": "1",
+    "10": False,
+    "13": 0,
+    "14": 0,
+    "15": 0,
+    "16": False,
+    "17": False,
+    "18": 78,
+    "19": False,
+}
+
+STIRLING_FS1_FAN_PAYLOAD = {
+    "1": True,
+    "2": "normal",
+    "3": 9,
+    "5": False,
+    "22": "cancel",
+}
+
+QOTO_SPRINKLER_PAYLOAD = {
+    "102": 100,
+    "103": 100,
+    "104": 10036,
+    "105": 10800,
+    "108": 0,
+}
+
+MINCO_MH1823D_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": "program",
+    "3": "stop",
+    "5": False,
+    "9": True,
+    "12": False,
+    "18": "out",
+    "19": "c",
+    "22": 18,
+    "23": 64,
+    "32": 1,
+    "33": 205,
+    "35": 0,
+    "37": 689,
+    "39": "7",
+    "45": 0,
+    "101": 200,
+    "102": 680,
+    "103": 0,
+    "104": 2,
+    "105": "no_power",
+    "106": 35,
+    "107": 95,
+}
+
+SIMPLE_GARAGE_DOOR_PAYLOAD = {
+    "1": True,
+    "101": False,
+}
+
+NEDIS_HTPL20F_PAYLOAD = {
+    "1": True,
+    "2": 25,
+    "3": 25,
+    "4": "1",
+    "7": False,
+    "11": "0",
+    "13": 0,
+    "101": False,
+}
+
+ASPEN_ASP200_FAN_PAYLOAD = {
+    "1": True,
+    "2": "in",
+    "3": 1,
+    "8": 0,
+    "18": 20,
+    "19": 25,
+    "101": True,
+    "102": 3,
+}
+
+TMWF02_FAN_PAYLOAD = {
+    "1": True,
+    "2": 0,
+    "3": "level_2",
+    "4": 40,
+}
+
+TIMED_SOCKET_PAYLOAD = {
+    "1": True,
+    "11": 0,
+}
+
+TIMED_SOCKETV2_PAYLOAD = {
+    "1": True,
+    "9": 0,
+}
+
+DIGOO_DGSP202_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "9": 0,
+    "10": 0,
+    "18": 500,
+    "19": 1200,
+    "20": 240,
+}
+
+DIGOO_DGSP01_SOCKET_PAYLOAD = {
+    "1": True,
+    "27": True,
+    "28": "colour",
+    "29": 76,
+    "31": "1c0d00001b640b",
+    "32": "3855b40168ffff",
+    "33": "ffff500100ff00",
+    "34": "ffff8003ff000000ff000000ff000000000000000000",
+    "35": "ffff5001ff0000",
+    "36": "ffff0505ff000000ff00ffff00ff00ff0000ff000000",
+}
+
+WOOX_R4028_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "3": True,
+    "7": True,
+    "101": 0,
+    "102": 0,
+    "103": 0,
+    "105": 0,
+}
+
+OWON_PCT513_THERMOSTAT_PAYLOAD = {
+    "2": "cool",
+    "16": 2150,
+    "17": 71,
+    "23": "c",
+    "24": 2950,
+    "29": 85,
+    "34": 52,
+    "45": 0,
+    "107": "0",
+    "108": 2150,
+    "109": 1650,
+    "110": 71,
+    "111": 62,
+    "115": "auto",
+    "116": "1",
+    "119": True,
+    "120": "permhold",
+    "123": 25,
+    "129": "coolfanon",
+}
+
+HYSEN_HY08WE2_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": 50,
+    "3": 170,
+    "4": "Manual",
+    "6": False,
+    "12": 0,
+    "101": False,
+    "102": False,
+    "103": 170,
+    "104": 4,
+    "105": 15,
+    "106": True,
+    "107": True,
+    "108": True,
+    "109": -10,
+    "110": 10,
+    "111": 2,
+    "112": 35,
+    "113": 5,
+    "114": 30,
+    "115": 5,
+    "116": "all",
+    "117": "keep",
+    "118": "2days",
+}
+
+POIEMA_ONE_PURIFIER_PAYLOAD = {
+    "1": True,
+    "2": 12,
+    "3": "manual",
+    "4": "mid",
+    "7": False,
+    "11": False,
+    "18": "cancel",
+    "19": 0,
+}
+
+ECOSTRAD_IQCERAMIC_RADIATOR_PAYLOAD = {
+    "1": True,
+    "2": "hot",
+    "16": 180,
+    "24": 90,
+    "27": 0,
+    "40": False,
+    "104": "15",
+    "107": "1",
+    "108": "0",
+    "109": "0",
+}
+
+NASHONE_MTS700WB_THERMOSTAT_PAYLOAD = {
+    "1": True,
+    "2": "hot",
+    "3": "manual",
+    "16": 20,
+    "17": 68,
+    "23": "c",
+    "24": 19,
+    "27": 0,
+    "29": 66,
+    "39": False,
+    "41": "cancel",
+    "42": 0,
+}
+
+LEFANT_M213_VACUUM_PAYLOAD = {
+    "1": True,
+    "2": False,
+    "3": "standby",
+    "4": "forward",
+    "5": "0",
+    "6": 91,
+    "13": False,
+    "16": 0,
+    "17": 0,
+    "18": 0,
+    "101": "nar",
+    "102": -23,
+    "103": 27,
+    "104": 0,
+    #   "106": "ChargeStage:DETSWITCGH",
+    #    "108": "BatVol:13159",
+}
+
+KYVOL_E30_VACUUM_PAYLOAD = {
+    "1": True,
+    "2": False,
+    "3": "standby",
+    "4": "stop",
+    "5": "Charging_Base",
+    "6": 2,
+    "7": 20,
+    "8": 60,
+    "9": 20,
+    "10": False,
+    "11": False,
+    "12": False,
+    "13": False,
+    "14": "3",
+    "16": 0,
+    "17": 0,
+    "18": 0,
+    "101": "2",
+    "102": "900234",
+    "104": "standby",
+    "107": 1,
+}
+
+HIMOX_H06_PURIFIER_PAYLOAD = {
+    "1": True,
+    "4": "low",
+    "5": 50,
+    "8": True,
+    "11": False,
+    "18": "cancel",
+    "19": 0,
+    "22": "medium",
+    "101": "calcle",
+}
+
+HIMOX_H05_PURIFIER_PAYLOAD = {
+    "1": True,
+    "2": 21,
+    "4": "auto",
+    "5": 92,
+    "7": False,
+    "11": False,
+    "18": "cancel",
+    "21": "good",
+}
+
+VORK_VK6067_PURIFIER_PAYLOAD = {
+    "1": True,
+    "4": "auto",
+    "5": 80,
+    "8": True,
+    "11": False,
+    "18": "cancel",
+    "19": 0,
+    "21": "good",
+    "22": 0,
+}
+
+KOGAN_GARAGE_DOOR_PAYLOAD = {
+    "101": "fopen",
+    "102": "opening",
+    "104": 100,
+    "105": True,
+}
+
+MOES_RGB_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": "colour",
+    "3": 255,
+    "4": 14,
+    "5": "ff99000024ffff",
+    "6": "bd76000168ffff",
+    "7": "ffff320100ff00",
+    "8": "ffff3203ff000000ff000000ff",
+    "9": "ffff3201ff0000",
+    "10": "ffff3205ff000000ff00ffff00ff00ff0000ff",
+    "101": True,
+    "102": 0,
+    "104": 0,
+    "105": 0,
+    "106": 2332,
+}
+
+LOGICOM_STRIPPY_PAYLOAD = {
+    "1": False,
+    "2": False,
+    "3": False,
+    "4": False,
+    "5": False,
+    "9": 0,
+    "10": 0,
+    "11": 0,
+    "12": 0,
+    "13": 0,
+}
+
+PARKSIDE_PLGS2012A1_PAYLOAD = {
+    "1": True,
+    "2": "test",
+    "3": 1000,
+    "4": 1320,
+    "5": 80,
+    "6": 25,
+    "7": "standard",
+    "8": False,
+    "9": True,
+    "10": 5,
+    "11": 0,
+    "101": 2500,
+    "102": 11,
+    "103": False,
+    "104": False,
+}
+
+SD123_PRESENCE_PAYLOAD = {
+    "1": "none",
+    "101": "0_meters",
+    "102": "6_meters",
+    "103": "case_0",
+    "104": "case_1",
+    "105": "not_reset",
+    "106": "normal",
+    "107": 1200,
+    "108": 1000,
+    "109": 1,
+    "110": 1,
+    "111": 10,
+    "112": 2,
+    "113": 0,
+    "114": True,
+}
+
+SIMPLE_BLINDS_PAYLOAD = {
+    "1": "stop",
+    "2": 0,
+    "5": False,
+    "7": "opening",
+}
+
+STARLIGHT_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": 260,
+    "3": 22,
+    "4": "hot",
+    "5": "auto",
+    "18": 0,
+    "20": 0,
+    "105": "off",
+    "110": 131644,
+    "113": "0",
+    "114": "0",
+    "119": "0",
+    "120": "off",
+    "123": "0018",
+    "126": "0",
+    "127": "0",
+    "128": "0",
+    "129": "1",
+    "130": 26,
+    "131": False,
+    "132": False,
+    "133": "0",
+    "134": '{"t":8601,"s":false,"clr":true}',
+}
+
+WILFA_HAZE_HUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "5": False,
+    "8": False,
+    "10": 20,
+    "13": 70,
+    "14": 55,
+    "16": False,
+    "18": "c",
+    "19": "cancel",
+    "20": 0,
+    "22": 0,
+    "23": "level_3",
+    "24": "humidity",
+    "26": False,
+    "35": False,
+}
+
+WEAU_POOL_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": 33,
+    "3": 195,
+    "4": "auto",
+    "6": 0,
+}
+
+WEAU_POOL_HEATPUMPV2_PAYLOAD = {
+    "1": True,
+    "2": "eheat",
+    "9": 15,
+    "10": 260,
+    "20": 0,
+    "101": 0,
+    "102": 40,
+    "103": 15,
+    "104": True,
+}
+
+SMARTPLUG_ENCODED_PAYLOAD = {
+    "1": True,
+    "11": 0,
+    "101": "QVA=",
+    "102": "QVA=",
+    "103": "QVA=",
+}
+
+DEVOLA_PATIO_HEATER_PAYLOAD = {
+    "1": True,
+    "2": 20,
+    "3": 15,
+    "4": "smart",
+    "5": "4",
+    "6": False,
+    "7": False,
+    "12": 0,
+    "14": "heating",
+    "19": "c",
+    "20": 68,
+    "21": 59,
+}
+
+QS_C01_CURTAIN_PAYLOAD = {
+    "1": "stop",
+    "2": 0,
+    "8": "forward",
+    "10": 20,
+}
+
+M027_CURTAIN_PAYLOAD = {
+    "1": "close",
+    "2": 0,
+    "4": "morning",
+    "7": "closing",
+    "10": 0,
+    "12": 0,
+    "101": False,
+}
+
+JIAHONG_ET72W_PAYLOAD = {
+    "101": True,
+    "102": 220,
+    "103": "Manual",
+    "104": 0,
+    "105": 205,
+    "106": 240,
+    "107": False,
+    "108": False,
+    "109": False,
+    "110": 2,
+    "111": "0",
+    "112": 0,
+    "113": 0,
+    "116": 500,
+    "117": 1234,
+    "118": True,
+    "121": 300,
+}
+
+BETTERLIFE_BL1500_PAYLOAD = {
+    "1": True,
+    "2": 20,
+    "4": "0",
+    "7": False,
+    "11": "0",
+    "12": 0,
+}
+
+EESEE_ADAM_PAYLOAD = {
+    "1": True,
+    "2": 50,
+    "4": "manual",
+    "5": "low",
+    "14": False,
+    "16": 72,
+    "17": "cancel",
+    "19": 0,
+}
+
+ALECOAIR_D14_PAYLOAD = {
+    "1": True,
+    "2": 50,
+    "4": "manual",
+    "5": "low",
+    "10": False,
+    "14": False,
+    "16": 72,
+    "17": "cancel",
+    "19": 0,
+}
+
+HYUNDAI_SAHARA_PAYLOAD = {
+    "1": True,
+    "2": 50,
+    "4": "high",
+    "6": 73,
+    "7": 25,
+    "14": False,
+    "16": False,
+    "19": 0,
+}
+
+RGBCW_LIGHTBULB_PAYLOAD = {
+    "20": True,
+    "21": "white",
+    "22": 1000,
+    "23": 500,
+    "24": "0000000003e8",
+    "25": "000e0d0000000000000000c80000",
+    "26": 0,
+}
+
+MOES_TEMP_HUMID_PAYLOAD = {
+    "1": True,
+    "2": False,
+    "3": True,
+    "4": "manual",
+    "6": 374,
+    "8": False,
+    "9": 0,
+    "11": False,
+    "12": 0,
+    "18": 0,
+    "20": 0,
+    "21": 0,
+    "22": 0,
+    "24": "",
+    "101": "",
+    "102": "",
+    "103": 0,
+    "104": 0,
+    "105": "off",
+    "106": "mix",
+}
+
+ORION_SMARTLOCK_PAYLOAD = {
+    "1": 0,
+    "2": 0,
+    "3": 0,
+    "4": 0,
+    "5": 0,
+    "8": 0,
+    "9": 0,
+    "10": False,
+    "12": 100,
+    "15": 0,
+    "16": False,
+}
+
+ELECTRIQ_AIRFLEX15W_PAYLOAD = {
+    "1": True,
+    "2": 16,
+    "3": 27,
+    "17": 90,
+    "20": 0,
+    "101": "1",
+    "103": False,
+    "104": "1",
+    "105": 0,
+    "106": False,
+    "109": False,
+    "112": 42,
+}
+
+PC321TY_POWERCLAMP_PAYLOAD = {
+    "101": 2284,
+    "102": 1073,
+    "103": 191,
+    "104": 78,
+    "106": 251,
+    "111": 2354,
+    "112": 748,
+    "113": 47,
+    "114": 100,
+    "116": 267,
+    "121": 2350,
+    "122": 753,
+    "123": 149,
+    "124": 84,
+    "126": 517,
+    "131": 1036,
+    "132": 2574,
+    "133": 188,
+    "135": 50,
+    "136": 390,
+}
+
+ENERGY_POWERSTRIP_PAYLOAD = {
+    "1": False,
+    "2": False,
+    "3": False,
+    "4": False,
+    "102": 0,
+    "103": 0,
+    "104": 2240,
+    "105": 1,
+    "106": 1709,
+    "107": 34620,
+    "108": 101000,
+    "109": 205,
+}
+
+COMPTEUR_SMARTMETER_PAYLOAD = {
+    "17": 12345,
+    "18": 2000,
+    "19": 4400,
+    "20": 2200,
+    "21": 0,
+    "22": 0,
+    "23": 0,
+    "24": 0,
+    "25": 0,
+    "26": 0,
+}
+
+BECOOL_HEATPUMP_PAYLOAD = {
+    "1": False,
+    "4": 0,
+    "5": "4",
+    "6": 24,
+    "8": "0",
+    "10": False,
+    "13": 0,
+    "14": 0,
+    "15": 0,
+    "16": True,
+    "17": False,
+    "19": False,
+}
+
+ESSENTIALS_PURIFIER_PAYLOAD = {
+    "1": True,
+    "2": 12,
+    "3": "auto",
+    "5": 50,
+    "7": False,
+    "9": False,
+    "11": False,
+    "18": "cancel",
+    "19": 0,
+    "21": "good",
+    "101": "Standard",
+}
+
+AVATTO_BLINDS_PAYLOAD = {
+    "1": "close",
+    "2": 0,
+    "3": 0,
+    "5": False,
+    "7": "closing",
+    "8": "cancel",
+    "9": 0,
+    "11": 0,
+}
+
+AVATTO_CURTAIN_PAYLOAD = {
+    "1": "stop",
+    "101": True,
+}
+
+ORION_SIREN_PAYLOAD = {
+    "1": "normal",
+    "5": "middle",
+    "6": True,
+    "7": 10,
+    "15": 0,
+    "20": True,
+}
+
+INKBIRD_SOUSVIDE_PAYLOAD = {
+    "101": False,
+    "102": "stop",
+    "103": 0,
+    "104": 297,
+    "105": 0,
+    "106": 0,
+    "107": 3,
+    "108": True,
+    "109": 0,
+    "110": 0,
+}
+
+HYDROTHERM_DYNAMICX8_PAYLOAD = {
+    "1": True,
+    "2": 65,
+    "3": 60,
+    "4": "STANDARD",
+    "21": 0,
+}
+
+TREATLIFE_DS02F_PAYLOAD = {
+    "1": True,
+    "2": 0,
+    "3": "level_2",
+}
+
+MOTION_LIGHT_PAYLOAD = {
+    "101": "mode_auto",
+    "102": False,
+    "103": 0,
+    "104": 249,
+    "105": 374,
+    "106": False,
+}
+
+BLITZWOLF_BWSH2_PAYLOAD = {
+    "1": True,
+    "3": "grade1",
+    "6": "close",
+    "19": "cancel",
+}
+
+BCOM_CAMERA_PAYLOAD = {
+    "101": True,
+    "103": False,
+    "104": False,
+    "106": "1",
+    "108": "0",
+    "109": "64GB",
+    "110": 1,
+    "111": False,
+    "115": "",
+    "117": 0,
+    "136": "",
+    "150": True,
+    "151": "1",
+    "162": False,
+    "231": "",
+    "232": False,
+}
+
+GX_AROMA_PAYLOAD = {
+    "1": True,
+    "2": "high",
+    "3": "cancel",
+    "4": 0,
+    "5": True,
+    "6": "colour",
+    "8": "b9fff500ab46ff",
+    "9": 0,
+}
+
+MOEBOT_PAYLOAD = {
+    "6": 41,
+    "101": "MOWING",
+    "102": 0,
+    "103": "MOWER_LEAN",
+    "104": True,
+    "105": 8,
+    "106": 1343,
+    "114": "AutoMode",
+}
+
+TOMPD63LW_SOCKET_PAYLOAD = {
+    "1": 139470,
+    "6": "CPQAFEkAAuk=",
+    "9": 0,
+    "11": False,
+    "12": False,
+    "13": 0,
+    "16": True,
+    "19": "FSE-F723C46A04FC6C",
+    # "101": 275,
+    # "102": 170,
+    # "103": 40,
+    # "104": 30,
+    # "105": False,
+    # "106": False,
+}
+
+GOLDAIR_GPDH340_PAYLOAD = {
+    "1": True,
+    "2": "2",
+    "4": 60,
+    "6": "2",
+    "11": 0,
+    "103": 20,
+    "104": 72,
+    "105": 40,
+    "106": False,
+    "107": True,
+    "108": False,
+    "109": False,
+}
+
+THERMEX_IF50V_PAYLOAD = {
+    "101": False,
+    "102": 37,
+    "104": 65,
+    "105": "2",
+    "106": 0,
+}
+
+ZXG30_ALARM_PAYLOAD = {
+    "1": "home",
+    "2": 0,
+    "3": 3,
+    "4": True,
+    "9": False,
+    "10": False,
+    "15": True,
+    "16": 100,
+    "17": True,
+    "20": False,
+    "21": False,
+    "22": 1,
+    "23": "2",
+    "24": "Normal",
+    "27": True,
+    "28": 10,
+    "29": True,
+    "32": "normal",
+    "34": False,
+    "35": False,
+    "36": "3",
+    "37": "0",
+    "39": "0",
+    "40": "1",
+}
+
+IR_REMOTE_SENSORS_PAYLOAD = {
+    "101": 200,
+    "102": 80,
+}
+
+LORATAP_CURTAINSWITCH_PAYLOAD = {
+    "1": "3",
+}
+
+BLE_WATERVALVE_PAYLOAD = {
+    "1": True,
+    "4": 0,
+    "7": 50,
+    "9": 3600,
+    "10": "cancel",
+    "12": "unknown",
+    "15": 60,
+}
+
+AM25_ROLLERBLIND_PAYLOAD = {
+    "1": "stop",
+    "2": 0,
+    "104": True,
+    "105": True,
+    "109": 4,
+}
+
+DUUX_BLIZZARD_PAYLOAD = {
+    "1": False,
+    "2": "fan",
+    "3": "high",
+    "4": 0,
+    "6": False,
+    "7": False,
+    "8": 22,
+    "9": 0,
+    "11": 72,
+    "12": True,
+    "13": False,
+    "14": False,
+    "15": 0,
+}
+
+BLE_SMARTPLANT_PAYLOAD = {
+    "3": 50,
+    "5": 25,
+    "9": "c",
+    "14": "Low",
+    "15": 20,
+}
+
+GOLDAIR_PORTABLE_AIR_CONDITIONER_PAYLOAD = {
+    "1": True,
+    "2": 22,
+    "3": 30,
+    "4": "cold",
+    "5": "low",
+    "11": False,
+    "15": "off",
+    "20": 0,
+    "103": False,
+    "104": 0,
+    "105": 0,
+    "107": 72,
+    "108": 80,
+    "109": 26,
+    "110": False,
+}