diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index b86b9a3..0040d8e 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -32,6 +32,7 @@ NO_ADDITIONAL_PLATFORMS = "no_additional_platforms" USER_SCHEMA = vol.Schema( { vol.Required(CONF_NAME): str, + vol.Required(CONF_FRIENDLY_NAME): str, vol.Required(CONF_HOST): str, vol.Required(CONF_DEVICE_ID): str, vol.Required(CONF_LOCAL_KEY): str, @@ -64,8 +65,8 @@ def strip_dps_values(user_input, fields): async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect.""" - pytuyadevice = pytuya.OutletDevice( - data[CONF_DEVICE_ID], data[CONF_HOST], data[CONF_LOCAL_KEY] + pytuyadevice = pytuya.PytuyaDevice( + data[CONF_DEVICE_ID], data[CONF_HOST], data[CONF_LOCAL_KEY], data[CONF_NAME] ) pytuyadevice.set_version(float(data[CONF_PROTOCOL_VERSION])) pytuyadevice.set_dpsUsed({}) @@ -180,9 +181,10 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): else: self.entities.append(_convert_entity(user_input)) - print('ENTITIES: [{}] '.format(self.entities)) + #print('ENTITIES: [{}] '.format(self.entities)) config = { - CONF_NAME: f"{user_input[CONF_FRIENDLY_NAME]} (YAML)", + CONF_NAME: f"{user_input[CONF_FRIENDLY_NAME]} (YAML)", + CONF_FRIENDLY_NAME: f"{user_input[CONF_FRIENDLY_NAME]} (YAML)", CONF_HOST: user_input[CONF_HOST], CONF_DEVICE_ID: user_input[CONF_DEVICE_ID], CONF_LOCAL_KEY: user_input[CONF_LOCAL_KEY], diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 7078343..d47a490 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -84,7 +84,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): #_LOGGER.info("conf_STOP_cmd is %s", config.get(CONF_STOP_CMD)) covers = [] - pytuyadevice = pytuya.PytuyaDevice(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY)) + pytuyadevice = pytuya.PytuyaDevice( + config_entry.data[CONF_DEVICE_ID], + config_entry.data[CONF_HOST], + config_entry.data[CONF_LOCAL_KEY], + config_entry.data[CONF_FRIENDLY_NAME], + config_entry.data[CONF_NAME], + ) pytuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION))) dps = {} dps[config.get(CONF_ID)]=None diff --git a/custom_components/localtuya/fan.py b/custom_components/localtuya/fan.py index 445c79c..e7087ad 100644 --- a/custom_components/localtuya/fan.py +++ b/custom_components/localtuya/fan.py @@ -58,7 +58,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): """Set up of the Tuya switch.""" from . import pytuya fans = [] - pytuyadevice = pytuya.PytuyaDevice(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY)) + pytuyadevice = pytuya.PytuyaDevice( + config_entry.data[CONF_DEVICE_ID], + config_entry.data[CONF_HOST], + config_entry.data[CONF_LOCAL_KEY], + config_entry.data[CONF_FRIENDLY_NAME], + config_entry.data[CONF_NAME], + ) pytuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION))) _LOGGER.debug("localtuya fan: setup_platform: %s", pytuyadevice) diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index dd07d20..ae0fdac 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -62,7 +62,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None): from . import pytuya lights = [] - pytuyadevice = pytuya.PytuyaDevice(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY)) + pytuyadevice = pytuya.PytuyaDevice( + config_entry.data[CONF_DEVICE_ID], + config_entry.data[CONF_HOST], + config_entry.data[CONF_LOCAL_KEY], + config_entry.data[CONF_FRIENDLY_NAME], + config_entry.data[CONF_NAME], + ) pytuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION))) bulb_device = TuyaCache(pytuyadevice) diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 1fd57a3..819dfa1 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -172,13 +172,9 @@ payload_dict = { } } -#class PytuyaDevice(XenonDevice): -# def __init__(self, dev_id, address, local_key=None, dev_type=None): -# super(PytuyaDevice, self).__init__(dev_id, address, local_key, dev_type) -#class XenonDevice(object): class PytuyaDevice(object): - def __init__(self, dev_id, address, local_key=None, connection_timeout=10): + def __init__(self, dev_id, address, local_key, friendly_name, name = "", connection_timeout=10): """ Represents a Tuya device. @@ -194,6 +190,8 @@ class PytuyaDevice(object): self.id = dev_id self.address = address self.local_key = local_key.encode('latin1') + self.friendly_name = friendly_name + self.name = name self.connection_timeout = connection_timeout self.version = 3.1 self.dev_type = 'type_0a' diff --git a/custom_components/localtuya/strings.json b/custom_components/localtuya/strings.json index 898b99d..288097b 100644 --- a/custom_components/localtuya/strings.json +++ b/custom_components/localtuya/strings.json @@ -16,6 +16,7 @@ "description": "Fill in the basic details and pick device type. The name entered here will be used to identify the integration itself (as seen in the `Integrations` page). You will name each sub-device in the following steps.", "data": { "name": "Name", + "friendly_name": "Friendly name", "host": "Host", "device_id": "Device ID", "local_key": "Local key", diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index 36aeb54..74b3c52 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -120,6 +120,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): config_entry.data[CONF_DEVICE_ID], config_entry.data[CONF_HOST], config_entry.data[CONF_LOCAL_KEY], + config_entry.data[CONF_FRIENDLY_NAME], + config_entry.data[CONF_NAME], ) pytuyadevice.set_version(float(config_entry.data[CONF_PROTOCOL_VERSION])) pytuyadevice.set_dpsUsed({}) @@ -250,13 +252,12 @@ class LocaltuyaSwitch(SwitchEntity): @property def device_info(self): - print("ZIO KEN DEVINFO [{}]".format(self._device) ) return { "identifiers": { # Serial numbers are unique identifiers within a specific domain - ("LocalTuya", self.unique_id) + ("LocalTuya", f"local_{self._device.unique_id}") }, - "name": "MyName", + "name": self._device._device.friendly_name, "manufacturer": "Tuya generic", "model": "SmartSwitch", "sw_version": "3.3", diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 6ed5cfc..1cb21bd 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -15,6 +15,7 @@ "description": "Fill in the basic details and pick device type. The name entered here will be used to identify the integration itself (as seen in the `Integrations` page). You will add entities and give them names in the following steps.", "data": { "name": "Name", + "friendly_name": "Friendly name", "host": "Host", "device_id": "Device ID", "local_key": "Local key",