diff --git a/custom_components/tuya_local/__init__.py b/custom_components/tuya_local/__init__.py index 513429b9d9..94ed7bea62 100644 --- a/custom_components/tuya_local/__init__.py +++ b/custom_components/tuya_local/__init__.py @@ -233,7 +233,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): get_device_id(entry.data), ) config = {**entry.data, **entry.options, "name": entry.title} - setup_device(hass, config) + await setup_device(hass, config) device_conf = get_config(entry.data[CONF_TYPE]) if device_conf is None: _LOGGER.error(NOT_FOUND, config[CONF_TYPE]) diff --git a/custom_components/tuya_local/config_flow.py b/custom_components/tuya_local/config_flow.py index 41973ed4bb..885a3abfcd 100644 --- a/custom_components/tuya_local/config_flow.py +++ b/custom_components/tuya_local/config_flow.py @@ -162,6 +162,10 @@ async def async_step_user(self, user_input=None): errors["base"] = "connection" schema = { + vol.Required( + CONF_DEVICE_ID, + default=config.get(CONF_DEVICE_ID, ""), + ): str, vol.Required( CONF_LOCAL_KEY, default=config.get(CONF_LOCAL_KEY, ""), diff --git a/custom_components/tuya_local/device.py b/custom_components/tuya_local/device.py index 939b15e4cc..c99b0a5be7 100644 --- a/custom_components/tuya_local/device.py +++ b/custom_components/tuya_local/device.py @@ -16,18 +16,21 @@ EVENT_HOMEASSISTANT_STOP, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import DeviceInfo + from .const import ( API_PROTOCOL_VERSIONS, CONF_DEVICE_ID, CONF_LOCAL_KEY, CONF_POLL_ONLY, + CONF_TYPE, CONF_PROTOCOL_VERSION, DOMAIN, CONF_DEVICE_CID, ) from .helpers.config import get_device_id -from .helpers.device_config import possible_matches +from .helpers.device_config import possible_matches, get_config, TuyaDeviceConfig from .helpers.log import log_json @@ -44,6 +47,7 @@ def __init__( protocol_version, dev_cid, hass: HomeAssistant, + config: TuyaDeviceConfig, poll_only=False, ): """ @@ -67,6 +71,7 @@ def __init__( self._api_protocol_version_index = None self._api_protocol_working = False self._api_working_protocol_failures = 0 + self._config = config try: if dev_cid is not None: self._api = tinytuya.Device( @@ -128,18 +133,22 @@ def unique_id(self): @property def device_info(self): """Return the device information for this device.""" - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "manufacturer": "Tuya", - } + device_info = DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + name=self.name, + default_manufacturer="Tuya", + manufacturer = self._config.manufacturer, + model = self._config.model, + ) + + return device_info @property def has_returned_state(self): """Return True if the device has returned some state.""" return len(self._get_cached_state()) > 1 - def actually_start(self, event=None): + async def actually_start(self, event=None): _LOGGER.debug("Starting monitor loop for %s", self.name) self._running = True self._shutdown_listener = self._hass.bus.async_listen_once( @@ -605,7 +614,7 @@ def get_key_for_value(obj, value, fallback=None): return keys[values.index(value)] if value in values else fallback -def setup_device(hass: HomeAssistant, config: dict): +async def setup_device(hass: HomeAssistant, config: dict): """Setup a tuya device based on passed in config.""" _LOGGER.info("Creating device: %s", get_device_id(config)) @@ -618,6 +627,7 @@ def setup_device(hass: HomeAssistant, config: dict): config[CONF_PROTOCOL_VERSION], config.get(CONF_DEVICE_CID), hass, + get_config(config[CONF_TYPE]), config[CONF_POLL_ONLY], ) hass.data[DOMAIN][get_device_id(config)] = {"device": device} diff --git a/custom_components/tuya_local/devices/README.md b/custom_components/tuya_local/devices/README.md index 83e4fff871..39bd68ac0b 100644 --- a/custom_components/tuya_local/devices/README.md +++ b/custom_components/tuya_local/devices/README.md @@ -14,25 +14,28 @@ The top level of the device configuration defines the following: ### `name` The device should be named descriptively with a name the user would recognize, -the brand and model of the device is a good choice. If a whole family of +the brand and model of the device is a good choice. If a whole family of devices is supported, a generalization of the model type can be used. The name should also indicate to the user what type of device it is. ### `products` -*Optional, for future use.* +_Optional, for future use._ -A list of products that this config applies to. Each product in the list must +A list of products that this config applies to. Each product in the list must have an `id` specified, which corresponds to the productId or productKey -(depending on where you are getting it from) in Tuya info. This is available +(depending on where you are getting it from) in Tuya info. This is available from the Tuya developer web portal listing for your device, or when using -UDP discovery (via tinytuya). In future it is intended that UDP discovery +UDP discovery (via tinytuya). In future it is intended that UDP discovery will be used to more precisely match devices to configs, so it is recommended -to report these if you can find them when requesting a new device. Each +to report these if you can find them when requesting a new device. Each listing can also have an optional `name`, which is intended to override the top level `name` when full support for this field is added. Probably other info will be added in future to provide better reporting of device manufacturer and model etc. +Currently the first values for `manufacturer` and `model` are mapped to the +device entry. If no values are specified `manufacturer` defaults to "Tuya" and +`model` to empty. ### `primary_entity` @@ -44,7 +47,7 @@ The configuration for entities is detailed in its own section below. ### `secondary_entities` -*Optional.* +_Optional._ This contains a list of additional Home Assistant entities providing additional functionality beyond the capabilities of the primary @@ -59,42 +62,42 @@ and is detailed in the section below. ### `entity` -The Home Assistant entity type being configured. Currently supported +The Home Assistant entity type being configured. Currently supported types are **climate**, **switch**, **light**, **lock**. Functionality for these entities is limited to that which has been required for the -devices until now and may need to be extended for new devices. In +devices until now and may need to be extended for new devices. In particular, the light and lock entities have only been used for simple secondary entities, so only basic functionality is implemented. ### `class` -*Optional.* +_Optional._ For some entity types, a device `class` can be set, for example `switch` -entities can have a class of `outlet`. This may slightly alter the UI +entities can have a class of `outlet`. This may slightly alter the UI behaviour. For most entities, it will alter the default icon, and for binary sensors also the state that off and on values translate to in the UI. ### `category` -*Optional.* +_Optional._ -This specifies the `entity category` of the entity. Entities can be categorized +This specifies the `entity category` of the entity. Entities can be categorized as `config` or `diagnostic` to restrict where they appear automatically in Home Assistant. ### `dps` This is a list of the definitions for the Tuya DPs associated with -attributes of this entity. There should be one list entry for each +attributes of this entity. There should be one list entry for each supported DPs reported by the device. The configuration of DPs entries is detailed in its own section below. ### `name` -*Optional.* +_Optional._ The name associated with this entity can be set here. If no name is set, it will inherit the name at the top level. This is mostly useful for @@ -104,10 +107,10 @@ name may not be sufficient to describe the function. ### `mode` -*Optional. For number entities, default="auto", for others, None* +_Optional. For number entities, default="auto", for others, None_ For number entities, this can be used to force `slider` or `box` as the -input method. The default `auto` uses a slider if the range is small enough, +input method. The default `auto` uses a slider if the range is small enough, or a box otherwise. ## DPs configuration @@ -120,19 +123,19 @@ Every DP must have a numeric ID matching the DP ID in the Tuya protocol. The type of data returned by the Tuya API. Can be one of the following: - - **string** can contain arbitrary text. - - **boolean** can contain the values **True** or **False**. - - **integer** can contain only numbers. Integers can have range set on them, be scaled and steped - - **bitfield** is a special case of integer, where the bits that make up the value each has individal meaning. - - **base64** is a special case of string, where binary data is base64 encoded. Platforms that use this type will need special handling to make sense of the data. - - **hex** is a special case of string, where binary data is hex encoded. Platforms that use this type will need special handling to make sense of the data. - - **json** is a special case of string, where multiple data points are encoded in json format in the string. Platforms that use this type will need special handling to make sense of the data. - - **float** can contain floating point numbers. No known devices use this, but it is supported if needed. +- **string** can contain arbitrary text. +- **boolean** can contain the values **True** or **False**. +- **integer** can contain only numbers. Integers can have range set on them, be scaled and steped +- **bitfield** is a special case of integer, where the bits that make up the value each has individal meaning. +- **base64** is a special case of string, where binary data is base64 encoded. Platforms that use this type will need special handling to make sense of the data. +- **hex** is a special case of string, where binary data is hex encoded. Platforms that use this type will need special handling to make sense of the data. +- **json** is a special case of string, where multiple data points are encoded in json format in the string. Platforms that use this type will need special handling to make sense of the data. +- **float** can contain floating point numbers. No known devices use this, but it is supported if needed. ### `name` The name given to the attribute in Home Assistant. Certain names are used -by the Home Assistant entities for specific purposes. If a name is not +by the Home Assistant entities for specific purposes. If a name is not recognized as a standard attribute by the entitiy implementation, the attribute will be returned as a readonly custom attribute on the entity. If you need non-standard attributes to be able to be set, you will need @@ -140,51 +143,51 @@ to use a secondary entity for that. ### `readonly` -*Optional, default false.* +_Optional, default false._ A boolean setting to mark attributes as readonly. If not specified, the -default is `false`. If set to `true`, the attributes will be reported +default is `false`. If set to `true`, the attributes will be reported to Home Assistant, but attempting to set them will result in an error. This is only needed in contexts where it would normally be possible to set -the value. If you are creating a sensor entity, or adding an attribute of an +the value. If you are creating a sensor entity, or adding an attribute of an entity which is inherently read-only, then you do not need to specify this. ### `optional` -*Optional, default false.* +_Optional, default false._ -A boolean setting to mark attributes as optional. This allows a device to be +A boolean setting to mark attributes as optional. This allows a device to be matched even if it is not sending the dp at the time when adding a new device. It can also be used to match a range of devices that have variations in the extra attributes that are sent. ### `persist` -*Optional, default true.* +_Optional, default true._ Whether to persist the value if the device does not return it on every status -refresh. Some devices don't return every value on every status poll. In most +refresh. Some devices don't return every value on every status poll. In most cases, it is better to remember the previous value, but in some cases the dp is used to signal an event, so when it is next sent, it should trigger -automations even if it is the same value as previously sent. In that case +automations even if it is the same value as previously sent. In that case the value needs to go to null in between when the device is not sending it. ### `force` -*Optional, default false.* +_Optional, default false._ A boolean setting to mark dps as requiring an explicit update request -to fetch. Many energy monitoring smartplugs require this, without a +to fetch. Many energy monitoring smartplugs require this, without a explicit request to update them, such plugs will only return monitoring data -rarely or never. Devices can misbehave if this is used on dps that do not -require it. Use this only where needed, and generally only on read-only dps. +rarely or never. Devices can misbehave if this is used on dps that do not +require it. Use this only where needed, and generally only on read-only dps. ### `precision` -*Optional, default None.* +_Optional, default None._ For integer dps that are sensor values, the suggested precision for -display in Home Assistant can be specified. If unspecified, the Home +display in Home Assistant can be specified. If unspecified, the Home Assistant will use the native precision, which is calculated based on the scale of the dp so as to provide distinct values with as few decimal places as possible. For example a scale of 3 will result in @@ -194,7 +197,7 @@ with by specifying the precision explicitly. ### `mapping` -*Optional.* +_Optional._ This can be used to define a list of additional rules that modify the DP to Home Assistant attribute mapping to something other than a one to one copy. @@ -206,14 +209,14 @@ defined in their own section below. ### `hidden` -*Optional, default false.* +_Optional, default false._ This can be used to define DPs that do not directly expose Home Assistant -attributes. When set to **true**, no attribute will be sent. A `name` should +attributes. When set to **true**, no attribute will be sent. A `name` should still be specified and the attribute can be referenced as a `constraint` from mapping rules on other attributes to implement complex mappings. An example of use is a climate device, where the Tuya device keeps separate -temperature settings for different Normal and Eco preset modes. The Normal +temperature settings for different Normal and Eco preset modes. The Normal temperature setting is exposed through the standard `temperature` Home Assistant attribute on the climate device, but the `eco_temperature` setting on a different DP is set to hidden. Mapping Rules are used on the @@ -222,138 +225,137 @@ is set to Eco. ### `range` -*Optional, may be required in some contexts, may have defaults in others.* +_Optional, may be required in some contexts, may have defaults in others._ For integer attributes that are not readonly, a range can be set with `min` and `max` values that will limit the values that the user can enter in the -Home Assistant UI. This can also be set in a `mapping` or `conditions` block. +Home Assistant UI. This can also be set in a `mapping` or `conditions` block. ### `unit` -*Optional, default="C" for temperature dps on climate devices.* +_Optional, default="C" for temperature dps on climate devices._ -For temperature dps, some devices will use Fahrenhiet. This needs to be -indicated back to HomeAssistant by defining `unit` as "F". For sensor +For temperature dps, some devices will use Fahrenhiet. This needs to be +indicated back to HomeAssistant by defining `unit` as "F". For sensor entities, see the HomeAssistant developer documentation for the full list of possible units (C and F are automatically translated to their Unicode equivalents, other units are currently ASCII so can be easily entered directly). ### `class` -*Optional.* +_Optional._ For sensors, this sets the state class of the sensor (measurement, total or total_increasing) - ### `format` -*Optional.* +_Optional._ For base64 and hex types, this specifies how to decode the binary data (after hex or base64 decoding). -This is a container field, the contents of which should be a list consisting of `name`, `bytes` and `range` fields. `range` is as described above. `bytes` is the number of bytes for the field, which can be `1`, `2`, or `4`. `name` is a name for the field, which will have special handling depending on +This is a container field, the contents of which should be a list consisting of `name`, `bytes` and `range` fields. `range` is as described above. `bytes` is the number of bytes for the field, which can be `1`, `2`, or `4`. `name` is a name for the field, which will have special handling depending on the device type. ### `mask` -*Optional.* +_Optional._ -For base64 and hex types, this specifies how to extract a single numeric value from the binary data. The value should be a hex bit mask (eg 00FF00 to extract the middle byte of a 3 byte value). Unlike format, this does not require special handling in the entity platform, as only a single value is being extracted. +For base64 and hex types, this specifies how to extract a single numeric value from the binary data. The value should be a hex bit mask (eg 00FF00 to extract the middle byte of a 3 byte value). Unlike format, this does not require special handling in the entity platform, as only a single value is being extracted. ## Mapping Rules Mapping rules can change the behavior of attributes beyond simple -copying of DP values to attribute values. Rules can be defined +copying of DP values to attribute values. Rules can be defined without a dps_val to apply to all values, or a list of rules that apply to particular dp values can be defined to change only -particular cases. Rules can even depend on the values of other +particular cases. Rules can even depend on the values of other elements. ### `dps_val` -*Optional, if not provided, the rule is a default that will apply to all -values not covered by their own dps_val rule.* +_Optional, if not provided, the rule is a default that will apply to all +values not covered by their own dps_val rule._ `dps_val` defines the DP value that each rule in the list applies to. This can be used to map specific values from the Tuya protocol into attribute values that have specific meaning in Home -Assistant. For example, climate entities in Home Assistant define modes +Assistant. For example, climate entities in Home Assistant define modes "off", "heat", "cool", "heat_cool", "auto" and "dry". But in the Tuya protocol, -a simple heater just has a boolean off/on switch. It can also be used to -change the icon when a specific mode is operational. For example if +a simple heater just has a boolean off/on switch. It can also be used to +change the icon when a specific mode is operational. For example if a heater device has a fan-only mode, you could change the icon to "mdi:fan" instead of "mdi:radiator" when in that mode. A `dps_val` of `null` can be used to specify a value to be assumed when a dp is not being returned by the device, to avoid None in some locations where -that causes an issue such as entities showing as unavailable. Such a mapping +that causes an issue such as entities showing as unavailable. Such a mapping is one-way, the value will not be mapped back to a null when setting the dp. ### `value` -*Optional.* +_Optional._ This can be used to set the attribute value seen by Home Assistant to something -different than the DP value from the Tuya protocol. Normally it will be used +different than the DP value from the Tuya protocol. Normally it will be used with `dps_val` to map from one value to another. Without `dps_val` it will -one-way map all otherwise unmapped dps values to the specified value. This +one-way map all otherwise unmapped dps values to the specified value. This can be useful for a binary_sensor. ### `hidden` -*Optional, default=false* +_Optional, default=false_ When set to true, the mapping value is hidden from the list of all values. This can be used for items that should not be available for selection by the -user but you still want to map for feedback coming from the device. For +user but you still want to map for feedback coming from the device. For example, some devices have a "Manual" mode, which is automatically selected when adjustments are made to other settings, but should not be available as an explicit mode for the user to select. ### `scale` -*Optional, default=1.* +_Optional, default=1._ -This can be used in an `integer` dp mapping to scale the values. For example +This can be used in an `integer` dp mapping to scale the values. For example some climate devices represent the temperature as an integer in tenths of degrees, and require a scale of 10 to convert them to degrees expected by -Home Assistant. The scale can also be the other way, for a fan with speeds +Home Assistant. The scale can also be the other way, for a fan with speeds 1, 2 and 3 as DP values, this can be converted to a percentage with a scale of 0.03. ### `invert` -*Optional, default=False.* +_Optional, default=False._ -This can be used in an `integer` dp mapping to invert the range. For example, +This can be used in an `integer` dp mapping to invert the range. For example, some cover devices have an opposite idea of which end of the percentage scale open -and closed are from what Home Assistant assumes. To use this mapping option, a range +and closed are from what Home Assistant assumes. To use this mapping option, a range must also be specified for the dp. ### `step` -*Optional, default=1.* +_Optional, default=1._ This can be used in an `integer` dp mapping to make values jump by a specific -step. It can also be set in a conditions block so that the steps change only -under certain conditions. An example is where a value has a range of 0-100, but +step. It can also be set in a conditions block so that the steps change only +under certain conditions. An example is where a value has a range of 0-100, but only allows settings that are divisible by 10, so a step of 10 would be set. ### `icon` -*Optional.* +_Optional._ -This can be used to override the icon. Most useful with a `dps_val` which +This can be used to override the icon. Most useful with a `dps_val` which indicates a change from normal operating mode, such as "fan-only", "defrosting", "tank-full" or some error state. ### `icon_priority` -*Optional. Default 10. Lower numbers mean higher priorities.* +_Optional. Default 10. Lower numbers mean higher priorities._ When a number of rules on different attributes define `icon` changes, you -may need to control which have priority over the others. For example, +may need to control which have priority over the others. For example, if the device is off, probably it is more important to indicate that than -whether it is in fan-only or heat mode. So in the off/on DP, you might +whether it is in fan-only or heat mode. So in the off/on DP, you might give a priority of 1 to the off icon, 3 to the on icon, and in the mode DP you could give a priority of 2 to the fan icon, to make it override the normal on icon, but not the off icon. @@ -363,48 +365,48 @@ icon will be displayed. ### `value_redirect` -*Optional.* +_Optional._ When `value_redirect` is set, the value of the attribute and any attempt to set it will be redirected to the named attribute instead of the current one. An example of how this can be useful is where a Tuya heater has a dp for the target temperature in normal mode, and a different dp for the target -temperature is "eco" mode. Depending on the `preset_mode`, you need to use +temperature is "eco" mode. Depending on the `preset_mode`, you need to use one or the other. But Home Assistant just has one `temperature` attribute for setting target temperature, so the mapping needs to be done before passing to Home Assistant. ### `value_mirror` -*Optional.* +_Optional._ When `value_mirror` is set, the value of the attribute will be redirected to -the current value of the named attribute. Unlike `value_redirect`, this does +the current value of the named attribute. Unlike `value_redirect`, this does not redirect attempts to set the dp to the redirected dp, but when used in a map, this can make the mapping dynamic. An example of how this can be useful is where a thermostat can be configured to control either a heating or cooling device, but it is not expected to -change this setting during operation. Once set up, the hvac_mode dp can +change this setting during operation. Once set up, the hvac_mode dp can have a mapping that mirrors the value of the configuration dp. ### `invalid` -*Optional, default false.* +_Optional, default false._ Invalid set to true allows an attribute to temporarily be set read-only in -some conditions. Rather than passing requests to set the attribute through +some conditions. Rather than passing requests to set the attribute through to the Tuya protocol, attempts to set it will throw an error while it meets -the conditions to be `invalid`. It does not make sense to set this at mapping +the conditions to be `invalid`. It does not make sense to set this at mapping level, as it would cause a situation where you can set a value then not be -able to unset it. Instead, this should be used with conditions, below, to +able to unset it. Instead, this should be used with conditions, below, to make the behaviour dependent on another DP, such as disabling fan speed control when the preset is in sleep mode (since sleep mode should force low). ### `default` -*Optional, default false.* +_Optional, default false._ Default set to true allows an attribute to be set as the default value. This is used by some entities when an argument is not provided to a service call @@ -415,16 +417,16 @@ pick a default tone to use to turn on the siren. ### `constraint` -*Optional, always paired with `conditions`. Default if unspecified is the current attribute* +_Optional, always paired with `conditions`. Default if unspecified is the current attribute_ If a rule depends on an attribute other than the current one, then `constraint` -can be used to specify the element that `conditions` applies to. `constraint` can also refer back to the same attribute - this can be useful for specifying conditional mappings, for example to support two different variants of a device in a single config file, where the only difference is the way they represent enum attributes. +can be used to specify the element that `conditions` applies to. `constraint` can also refer back to the same attribute - this can be useful for specifying conditional mappings, for example to support two different variants of a device in a single config file, where the only difference is the way they represent enum attributes. ### `conditions` -*Optional, usually paired with `constraint.`* +_Optional, usually paired with `constraint.`_ -Conditions defines a list of rules that are applied based on the `constraint` attribute. The contents are the same as Mapping Rules, but `dps_val` applies to the attribute specified by `constraint`, and also can be a list of values to match as well rather than a single value. All others act on the current attribute as they would in the mapping. Although conditions are specified within a mapping, they can also contain a `mapping` of their own to override that mapping. These nested mappings are limited to simple `dps_val` to `value` substitutions, as more complex rules would quickly become too complex to manage. +Conditions defines a list of rules that are applied based on the `constraint` attribute. The contents are the same as Mapping Rules, but `dps_val` applies to the attribute specified by `constraint`, and also can be a list of values to match as well rather than a single value. All others act on the current attribute as they would in the mapping. Although conditions are specified within a mapping, they can also contain a `mapping` of their own to override that mapping. These nested mappings are limited to simple `dps_val` to `value` substitutions, as more complex rules would quickly become too complex to manage. When setting a dp which has conditions attached, the behaviour is slightly different depending on whether the constraint dp is readonly or not. @@ -433,6 +435,7 @@ For non-readonly constraints that specify a single dps_val, the constraint dp wi For readonly constraints, the condition must match the constraint dp's current value for anything to be set. **Example** + ```yaml ... name: target_dp @@ -452,89 +455,92 @@ For readonly constraints, the condition must match the constraint dp's current v - dps_val: c value: y ``` + If `constraint_dp` is not readonly: -| constraint_dp current dps_val | target_dp target value | dps set | -|---|---|---| -| a | x | target_dp: 1, constraint_dp: a | -| a | y | target_dp: 2, constraint_dp: c | -| a | z | target_dp: 1, constraint_dp: c | -| b | x | target_dp: 1, constraint_dp: a | -| b | y | target_dp: 2, constraint_dp: c | -| b | z | target_dp: 1, constraint_dp: c | -| c | x | target_dp: 1, constraint_dp: a | -| c | y | target_dp: 2, constraint_dp: c | -| c | z | target_dp: 1, constraint_dp: c | +| constraint_dp current dps_val | target_dp target value | dps set | +| ----------------------------- | ---------------------- | ------------------------------ | +| a | x | target_dp: 1, constraint_dp: a | +| a | y | target_dp: 2, constraint_dp: c | +| a | z | target_dp: 1, constraint_dp: c | +| b | x | target_dp: 1, constraint_dp: a | +| b | y | target_dp: 2, constraint_dp: c | +| b | z | target_dp: 1, constraint_dp: c | +| c | x | target_dp: 1, constraint_dp: a | +| c | y | target_dp: 2, constraint_dp: c | +| c | z | target_dp: 1, constraint_dp: c | If `constraint_dp` is readonly: -| current constraint_dp | target target_dp | dps set | -|---|---|---| -| a | x | target_dp: 1 | -| a | y | - | -| a | z | - | -| b | x | target_dp: 2 | -| b | y | - | -| b | z | - | -| c | x | - | -| c | y | target_dp: 2 | -| c | z | target_dp: 1 | - - +| current constraint_dp | target target_dp | dps set | +| --------------------- | ---------------- | ------------ | +| a | x | target_dp: 1 | +| a | y | - | +| a | z | - | +| b | x | target_dp: 2 | +| b | y | - | +| b | z | - | +| c | x | - | +| c | y | target_dp: 2 | +| c | z | target_dp: 1 | ## Entity types -Entities have specific mappings of dp names to functions. Any unrecognized dp name is added +Entities have specific mappings of dp names to functions. Any unrecognized dp name is added to the entity as a read-only extra attribute, so can be observed and queried from HA, but if you need to be able to change it, you should split it into its own entity of an appropriate type (number, select, switch for example). If the type of dp does not match the expected type, a mapping should be provided to convert. Note that "on" and "off" require quotes in yaml, otherwise it they are interpretted as true/false. -Many entity types support a class attribute which may change the UI behaviour, icons etc. See the +Many entity types support a class attribute which may change the UI behaviour, icons etc. See the HA documentation for the entity type to see what is valid (these may expand over time) ### `alarm_control_panel` -- **alarm_state** (required, string) the alarm state, used to report and change the current state of the alarm. Expects values from the set `disarmed`, `armed_home`, `armed_away`, `armed_night`, `armed_vacation`, `armed_custom_bypass`, `pending`, `arming`, `disarming`, `triggered`. Other states are allowed for read-only status, but only the armed... and disarmed states are available as commands. + +- **alarm_state** (required, string) the alarm state, used to report and change the current state of the alarm. Expects values from the set `disarmed`, `armed_home`, `armed_away`, `armed_night`, `armed_vacation`, `armed_custom_bypass`, `pending`, `arming`, `disarming`, `triggered`. Other states are allowed for read-only status, but only the armed... and disarmed states are available as commands. - **trigger** (optional, boolean) used to trigger the alarm remotely for test or panic button etc. ### `binary_sensor` + - **sensor** (required, boolean) the dp to attach to the sensor. ### `button` -- **button** (required, boolean) the dp to attach to the button. Any -read value will be ignored, but the dp is expected to be present for -device detection unless set to optional. A value of true will be sent -for a button press, map this to the desired dps_val if a different -value is required. + +- **button** (required, boolean) the dp to attach to the button. Any + read value will be ignored, but the dp is expected to be present for + device detection unless set to optional. A value of true will be sent + for a button press, map this to the desired dps_val if a different + value is required. ### `climate` + - **aux_heat** (optional, boolean) a dp to control the aux heat switch if the device has one. - **current_temperature** (optional, number) a dp that reports the current temperature. - **current_humidity** (optional, number) a dp that reports the current humidity (%). - **fan_mode** (optional, mapping of strings) a dp to control the fan mode if available. - Any value is allowed, but HA has some standard modes: - `"on", "off", auto, low, medium, high, top, middle, focus, diffuse` + Any value is allowed, but HA has some standard modes: + `"on", "off", auto, low, medium, high, top, middle, focus, diffuse` - **humidity** (optional, number) a dp to control the target humidity if available. (%) - **hvac_mode** (optional, mapping of strings) a dp to control the mode of the device. - Possible values are: `"off", cool, heat, heat_cool, auto, dry, fan_only` + Possible values are: `"off", cool, heat, heat_cool, auto, dry, fan_only` - **hvac_action** (optional, string) a dp thar reports the current action of the device. - Possible values are: `"off", idle, cooling, heating, drying, fan` + Possible values are: `"off", idle, cooling, heating, drying, fan` - **preset_mode** (optional, mapping of strings) a dp to control preset modes of the device. - Any value is allowed, but HA has some standard presets: - `none, eco, away, boost, comfort, home, sleep, activity` + Any value is allowed, but HA has some standard presets: + `none, eco, away, boost, comfort, home, sleep, activity` - **swing_mode** (optional, mapping of strings) a dp to control swing modes of the device. - Possible values are: `"off", vertical, horizontal` + Possible values are: `"off", vertical, horizontal` - **temperature** (optional, number) a dp to set the target temperature of the device. - A unit may be specified as part of the attribute if a temperature_unit dp is not available, if not - the default unit configured in HA will be used. + A unit may be specified as part of the attribute if a temperature_unit dp is not available, if not + the default unit configured in HA will be used. - **target_temp_high** (optional, number) a dp to set the upper temperature range of the device. - This dp should be paired with `target_temp_low`, and is mutually exclusive with `temperature` + This dp should be paired with `target_temp_low`, and is mutually exclusive with `temperature` - **target_temp_low** (optional, number) a dp to set the lower temperature range of the device. - **temperature_unit** (optional, string) a dp that specifies the unit the device is configured for. - Values should be mapped to "C" or "F" (case sensitive) - often the device will use a boolean or - lower case for this -- **min_temperature** (optional, number) a dp that specifies the minimum temperature that can be set. Some devices provide this, otherwise a fixed range on the temperature dp can be used. + Values should be mapped to "C" or "F" (case sensitive) - often the device will use a boolean or + lower case for this +- **min_temperature** (optional, number) a dp that specifies the minimum temperature that can be set. Some devices provide this, otherwise a fixed range on the temperature dp can be used. - **max_temperature** (optional, number) a dp that specifies the maximum temperature that can be set. ### `cover` @@ -542,45 +548,49 @@ value is required. Either **position** or **open** should be specified. - **position** (optional, number 0-100): a dp to control the percentage that the cover is open. - 0 means completely close, 100 means completely open. + 0 means completely close, 100 means completely open. - **control** (optional, mapping of strings): a dp to control the cover. Mainly useful if **position** cannot be used. - Valid values are `open, close, stop` + Valid values are `open, close, stop` - **action** (optional, string): a dp that reports the current state of the cover. - Special values are `opening, closing` + Special values are `opening, closing` - **open** (optional, boolean): a dp that reports if the cover is open. Only used if **position** is not available. ### `fan` + - **switch** (optional, boolean): a dp to control the power state of the fan - **preset_mode** (optional, mapping of strings): a dp to control different modes of the fan. - Values `"off", low, medium, high` used to be handled specially by HA as deprecated speed aliases. If these are the only "presets", consider mapping them as **speed** values instead, as voice assistants will respond to phrases like "turn the fan up/down" for speed. + Values `"off", low, medium, high` used to be handled specially by HA as deprecated speed aliases. If these are the only "presets", consider mapping them as **speed** values instead, as voice assistants will respond to phrases like "turn the fan up/down" for speed. - **speed** (optional, number 0-100): a dp to control the speed of the fan (%). - scale and step can be used to convert smaller ranges to percentages, or a mapping for discrete values. + scale and step can be used to convert smaller ranges to percentages, or a mapping for discrete values. - **oscillate** (optional, boolean): a dp to control whether the fan will oscillate or not. - **direction** (optional, string): a dp to control the spin direction of the fan. - Valid values are `forward, reverse`. + Valid values are `forward, reverse`. ### `humidifier` + Humidifer can also cover dehumidifiers (use class to specify which). - **switch** (optional, boolean): a dp to control the power state of the fan - **mode** (optional, mapping of strings): a dp to control preset modes of the device -- **humidity** (optional, number): a dp to control the target humidity of the device +- **humidity** (optional, number): a dp to control the target humidity of the device ### `light` + - **switch** (optional, boolean): a dp to control the on/off state of the light - **brightness** (optional, number 0-255): a dp to control the dimmer if available. - **color_temp** (optional, number): a dp to control the color temperature if available. - will be mapped so the minimum corresponds to 153 mireds (6500K), and max to 500 (2000K). -- **rgbhsv** (optional, hex): a dp to control the color of the light, using encoded RGB and HSV values. The `format` field names recognized for decoding this field are `r`, `g`, `b`, `h`, `s`, `v`. + will be mapped so the minimum corresponds to 153 mireds (6500K), and max to 500 (2000K). +- **rgbhsv** (optional, hex): a dp to control the color of the light, using encoded RGB and HSV values. The `format` field names recognized for decoding this field are `r`, `g`, `b`, `h`, `s`, `v`. - **color_mode** (optional, mapping of strings): a dp to control which mode to use if the light supports multiple modes. - Special values: `white, color_temp, hs, xy, rgb, rgbw, rgbww`, others will be treated as effects, - Note: only white, color_temp and hs are currently supported, others listed above are reserved and may be implemented in future when the need arises. - If no `color_mode` dp is available, a single supported color mode will be - calculated based on which of the above dps are available. + Special values: `white, color_temp, hs, xy, rgb, rgbw, rgbww`, others will be treated as effects, + Note: only white, color_temp and hs are currently supported, others listed above are reserved and may be implemented in future when the need arises. + If no `color_mode` dp is available, a single supported color mode will be + calculated based on which of the above dps are available. - **effect** (optional, mapping of strings): a dp to control effects / presets supported by the light. - Note: If the light mixes in color modes in the same dp, `color_mode` should be used instead. If the light contains both a separate dp for effects/scenes/presets and a mix of color_modes and effects (commonly scene and music) in the `color_mode` dp, then a separate select entity should be used for the dedicated dp to ensure the effects from `color_mode` are selectable. + Note: If the light mixes in color modes in the same dp, `color_mode` should be used instead. If the light contains both a separate dp for effects/scenes/presets and a mix of color_modes and effects (commonly scene and music) in the `color_mode` dp, then a separate select entity should be used for the dedicated dp to ensure the effects from `color_mode` are selectable. ### `lock` + - **lock** (optional, boolean): a dp to control the lock state: true = locked, false = unlocked - **unlock_fingerprint** (optional, integer): a dp to identify the fingerprint used to unlock the lock. - **unlock_password** (optional, integer): a dp to identify the password used to unlock the lock. @@ -593,57 +603,63 @@ Humidifer can also cover dehumidifiers (use class to specify which). - **jammed** (optional, boolean): a dp to signal that the lock is jammed. ### `number` + - **value** (required, number): a dp to control the number that is set. - **unit** (optional, string): a dp that reports the units returned by the number. - This may be useful for devices that switch between C and F, otherwise a fixed unit attribute on the **value** dp can be used. + This may be useful for devices that switch between C and F, otherwise a fixed unit attribute on the **value** dp can be used. - **minimum** (optional, number): a dp that reports the minimum the number can be set to. - This may be used as an alternative to a range setting on the **value** dp if the range is dynamic + This may be used as an alternative to a range setting on the **value** dp if the range is dynamic - **maximum** (optional, number): a dp that reports the maximum the number can be set to. - This may be used as an alternative to a range setting on the **value** dp if the range is dynamic + This may be used as an alternative to a range setting on the **value** dp if the range is dynamic ### `select` + - **option** (required, mapping of strings): a dp to control the option that is selected. ### `sensor` + - **sensor** (required, number or string): a dp that returns the current value of the sensor. - **unit** (optional, string): a dp that returns the unit returned by the sensor. - This may be useful for devices that switch between C and F, otherwise a fixed unit attribute on the **sensor** dp can be used. + This may be useful for devices that switch between C and F, otherwise a fixed unit attribute on the **sensor** dp can be used. ### `siren` + - **tone** (required, mapping of strings): a dp to report and control the siren tone. As this is used to turn on and off the siren, it is required. If this does not fit your siren, the underlying implementation will need to be modified. -The value "off" will be used for turning off the siren, and will be filtered from the list of available tones. One value must be marked as `default: true` so that the `turn_on` service with no commands works. + The value "off" will be used for turning off the siren, and will be filtered from the list of available tones. One value must be marked as `default: true` so that the `turn_on` service with no commands works. - **volume** (optional, float in range 0.0-1.0): a dp to control the volume of the siren (probably needs a scale and step applied, since Tuya devices will probably use an integer, or strings with fixed values). - **duration** (optional, integer): a dp to control how long the siren will sound for. ### `switch` + - **switch** (required, boolean): a dp to control the switch state. ### `vacuum` + - **status** (required, mapping of strings): a dp to report and control the status of the vacuum. -- **command** (optional, mapping of strings): a dp to control the statuss of the vacuum. If supplied, the status dp is only used to report the state. - Special values: `return_to_base, clean_spot`, others are sent as general commands +- **command** (optional, mapping of strings): a dp to control the statuss of the vacuum. If supplied, the status dp is only used to report the state. + Special values: `return_to_base, clean_spot`, others are sent as general commands - **locate** (optional, boolean): a dp to trigger a locator beep on the vacuum. - **power** (optional, boolean): a dp to switch full system power on and off - **activate** (optional, boolean): a dp to start and pause the vacuum - **battery** (optional, number 0-100): a dp that reports the current battery level (%) - **direction_control** (optional, mapping of strings): a dp that is used for directional commands - These are additional commands that are not part of **status**. They can be sent as general commands from HA. + These are additional commands that are not part of **status**. They can be sent as general commands from HA. - **error** (optional, bitfield): a dp that reports error status. - As this is mapped to a single "fault" state, you could consider separate binary_sensors to report on individual errors + As this is mapped to a single "fault" state, you could consider separate binary_sensors to report on individual errors ### `water_heater` + - **current_temperature** (optional, number): a dp that reports the current water temperature. -- **operation_mode** (optional, mapping of strings): a dp to report and control the operation mode of the water heater. If `away` is one of the modes, another mode must be marked as `default: true` to that the `away_mode_off` service knows which mode to switch out of away mode to. +- **operation_mode** (optional, mapping of strings): a dp to report and control the operation mode of the water heater. If `away` is one of the modes, another mode must be marked as `default: true` to that the `away_mode_off` service knows which mode to switch out of away mode to. - **temperature** (optional, number): a dp to control the target water temperature of the water heater. A unit may be specified as an attribute if the `temperature_unit` dp is not available, otherwise the default of HA's current setting will be used. - **temperature_unit** (optional, string): a dp that reports the unit the device is configured for. - Values should be mapped to "C" or "F" (case sensitive) - often the device will use a boolean or lower case for this + Values should be mapped to "C" or "F" (case sensitive) - often the device will use a boolean or lower case for this - **min_temperature** (optional, number): a dp that reports the minimum temperature the water heater can be set to, in case this is not a fixed value. -- **max_temperature** (optional, number): a dp that reports the maximum temperature the water heater can be set to, in case this is not a fixed value. +- **max_temperature** (optional, number): a dp that reports the maximum temperature the water heater can be set to, in case this is not a fixed value. - **away_mode** (optional, boolean): a dp to control whether the water heater is in away mode. - diff --git a/custom_components/tuya_local/devices/diivoo_wt05.yaml b/custom_components/tuya_local/devices/diivoo_wt05.yaml index ac0bc23674..bf052e8391 100644 --- a/custom_components/tuya_local/devices/diivoo_wt05.yaml +++ b/custom_components/tuya_local/devices/diivoo_wt05.yaml @@ -13,9 +13,10 @@ # "117": "OFF" rain (d) name: Diivoo smart dual water timer -product: +products: - id: fdrbxxbg model: WT-05 + manufacturer: Diivoo primary_entity: entity: switch name: Water Switch 1 diff --git a/custom_components/tuya_local/devices/electriq_ecosilent14hpw_aircon.yaml b/custom_components/tuya_local/devices/electriq_ecosilent14hpw_aircon.yaml index a2d1ea48a7..55a5afde8b 100644 --- a/custom_components/tuya_local/devices/electriq_ecosilent14hpw_aircon.yaml +++ b/custom_components/tuya_local/devices/electriq_ecosilent14hpw_aircon.yaml @@ -1,4 +1,8 @@ name: ElectriQ EcoSilent14HPW +products: + - id: nizrlkzey4fstckp + model: EcoSilent14HPW + manufacturer: ElectriQ primary_entity: entity: climate dps: @@ -106,10 +110,12 @@ primary_entity: name: current_temperature_f type: integer hidden: true + optional: true - id: 24 name: temperature_f type: integer hidden: true + optional: true - id: 101 name: swing_mode type: boolean diff --git a/custom_components/tuya_local/devices/water_timer_sop10.yaml b/custom_components/tuya_local/devices/water_timer_sop10.yaml index eb098844e9..3a4861f16b 100644 --- a/custom_components/tuya_local/devices/water_timer_sop10.yaml +++ b/custom_components/tuya_local/devices/water_timer_sop10.yaml @@ -1,6 +1,6 @@ # {"updated_at": 1686480325.6967278, "1": false, "7": 100, "9": 24707, "10": "cancel", "11": 0, "12": "idle", "14": false, "15": 1212} name: Smart Water Timer -product: +products: - id: nxquc5lb model: SOP10 primary_entity: diff --git a/custom_components/tuya_local/helpers/device_config.py b/custom_components/tuya_local/helpers/device_config.py index 3609e8d2e0..a452de4297 100644 --- a/custom_components/tuya_local/helpers/device_config.py +++ b/custom_components/tuya_local/helpers/device_config.py @@ -131,6 +131,22 @@ def primary_entity(self): primary=True, ) + @property + def model(self): + """Return the (first) device model if available""" + try: + return self._config["products"][0]["model"] + except (IndexError, KeyError): + pass + + @property + def manufacturer(self): + """Return the (first) device manufacturer if available""" + try: + return self._config["products"][0]["manufacturer"] + except (IndexError, KeyError): + pass + def secondary_entities(self): """Iterate through entites for any secondary entites supported.""" for conf in self._config.get("secondary_entities", {}): @@ -159,6 +175,18 @@ def matches(self, dps): [{dp.id: dp.type.__name__} for dp in incorrect_type_dps], ) + if "ecosil" in self._fname: + _LOGGER.warning( + "Not match for %s, DPs have incorrect type: %s", + self.name, + [{dp.id: dp.type.__name__} for dp in incorrect_type_dps], + ) + _LOGGER.warning( + "Not match for %s, missing required DPs: %s", + self.name, + [{dp.id: dp.type.__name__} for dp in missing_dps], + ) + return len(missing_dps) == 0 and len(incorrect_type_dps) == 0 def _get_all_dps(self): diff --git a/custom_components/tuya_local/translations/bg.json b/custom_components/tuya_local/translations/bg.json index 516a93d01c..c096866bba 100644 --- a/custom_components/tuya_local/translations/bg.json +++ b/custom_components/tuya_local/translations/bg.json @@ -42,6 +42,7 @@ "title": "Конфигуриране на вашето Tuya Local устройство", "description": "[Следвайте тези инструкции, за да откриете своя локален ключ.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "IP адрес или име на хост", "local_key": "Локален ключ", "protocol_version": "Версия на протокола (опитайте автоматична, ако не е известна)", diff --git a/custom_components/tuya_local/translations/en.json b/custom_components/tuya_local/translations/en.json index 46ad2ecd88..56b33de579 100644 --- a/custom_components/tuya_local/translations/en.json +++ b/custom_components/tuya_local/translations/en.json @@ -43,6 +43,7 @@ "title": "Configure your Tuya Local device", "description": "[Follow these instructions to find your local key.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "IP address or hostname", "local_key": "Local key", "protocol_version": "Protocol version (try auto if not known)", diff --git a/custom_components/tuya_local/translations/es.json b/custom_components/tuya_local/translations/es.json index f52675ec64..b97f310826 100644 --- a/custom_components/tuya_local/translations/es.json +++ b/custom_components/tuya_local/translations/es.json @@ -41,6 +41,7 @@ "title": "Configura tu dispositivo Tuya Local", "description": "[Siga estas instrucciones para encontrar su clave local.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Identificación del dispositivo (uuid)", "host": "Dirección IP o nombre de host", "local_key": "Clave local (Local key)", "protocol_version": "Versión del protocolo (pruebe automático si no lo sabe)" diff --git a/custom_components/tuya_local/translations/fr.json b/custom_components/tuya_local/translations/fr.json index 5e449fe2a3..8f797d9685 100644 --- a/custom_components/tuya_local/translations/fr.json +++ b/custom_components/tuya_local/translations/fr.json @@ -43,6 +43,7 @@ "title": "Configurer votre appareil Tuya Local", "description": "[Suivre ces instructions pour trouver le 'device id' et la 'local key'.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "Adresse IP ou Nom d'hote", "local_key": "Local key", "protocol_version": "Version du Protocole (Auto si inconnu)", diff --git a/custom_components/tuya_local/translations/hu.json b/custom_components/tuya_local/translations/hu.json index 7c99aebde0..7f8dee6be0 100644 --- a/custom_components/tuya_local/translations/hu.json +++ b/custom_components/tuya_local/translations/hu.json @@ -42,6 +42,7 @@ "title": "Állítsd be a helyi Tuya eszközödet", "description": "[Kövesd ezeket az utasításokat, hogy megtalált a helyi kulcsot (local_key).](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Eszköz azonosító (device_id - uuid)", "host": "IP cím vagy állomásnév", "local_key": "Helyi kulcs (local_key)", "protocol_version": "Protokol verzió (hagyd auto-n, ha nem tudod)", diff --git a/custom_components/tuya_local/translations/it.json b/custom_components/tuya_local/translations/it.json index 88380bf19b..e3efcbe71b 100644 --- a/custom_components/tuya_local/translations/it.json +++ b/custom_components/tuya_local/translations/it.json @@ -42,6 +42,7 @@ "title": "Configura il tuo dispositivo Tuya Local", "description": "[Segui queste istruzioni per trovare 'device id' e 'local key'.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "Indirizzo IP o nome host", "local_key": "Local key", "protocol_version": "Versione protocollo (prova 'auto' in caso di dubbi)", diff --git a/custom_components/tuya_local/translations/pt-BR.json b/custom_components/tuya_local/translations/pt-BR.json index 22759a3217..88f620ddc3 100644 --- a/custom_components/tuya_local/translations/pt-BR.json +++ b/custom_components/tuya_local/translations/pt-BR.json @@ -42,6 +42,7 @@ "title": "Configure seu dispositivo Tuya Local", "description": "[Siga estas instruções para encontrar o ID do seu dispositivo e a chave local.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "Endereço IP ou nome do host", "local_key": "Chave Local", "protocol_version": "Versão do protocolo (tente auto se não souber)", diff --git a/custom_components/tuya_local/translations/ru.json b/custom_components/tuya_local/translations/ru.json index 9cc8c6fddf..173f5d0904 100644 --- a/custom_components/tuya_local/translations/ru.json +++ b/custom_components/tuya_local/translations/ru.json @@ -43,6 +43,7 @@ "title": "Настройте свое Tuya Local устройство", "description": "[Следуйте этим инструкциям, чтобы найти свой локальный ключ.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Device ID (uuid)", "host": "IP address or hostname", "local_key": "Local key", "protocol_version": "Версия протокола (попробуйте auto, если не известна)", diff --git a/custom_components/tuya_local/translations/uk.json b/custom_components/tuya_local/translations/uk.json index 541b6c3670..5bdcec1758 100644 --- a/custom_components/tuya_local/translations/uk.json +++ b/custom_components/tuya_local/translations/uk.json @@ -42,6 +42,7 @@ "title": "Налаштуйте свій пристрій Tuya Local", "description": "[Дотримуйтеся цих інструкцій, щоб знайти локальний ключ.](https://github.com/make-all/tuya-local#finding-your-device-id-and-local-key)", "data": { + "device_id": "Ідентифікатор пристрою (uuid)", "host": "IP-адреса або ім'я хоста", "local_key": "Локальний ключ (local_key)", "protocol_version": "Версія протоколу (якщо не знаєте, спробуйте 'auto')",