diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index ad29b32..b83a244 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -50,8 +50,6 @@ def prepare_setup_entities(config_entry, platform): 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], ) device.set_version(float(config_entry.data[CONF_PROTOCOL_VERSION])) device.set_dpsUsed({}) diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index 0135e80..a58c096 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -32,7 +32,6 @@ 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, @@ -77,8 +76,6 @@ async def validate_input(hass: core.HomeAssistant, data): data[CONF_DEVICE_ID], data[CONF_HOST], data[CONF_LOCAL_KEY], - data[CONF_FRIENDLY_NAME], - data[CONF_NAME], ) pytuyadevice.set_version(float(data[CONF_PROTOCOL_VERSION])) pytuyadevice.set_dpsUsed({}) diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 8ece378..70e7a24 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -84,7 +84,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): dps[device_config[CONF_ID]] = None covers.append( LocaltuyaCover( - TuyaCache(device), + TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]), device_config[CONF_FRIENDLY_NAME], device_config[CONF_ID], device_config.get(CONF_OPEN_CMD), @@ -107,11 +107,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class TuyaCache: """Cache wrapper for pytuya.TuyaDevice""" - def __init__(self, device): + def __init__(self, device, friendly_name): """Initialize the cache.""" self._cached_status = "" self._cached_status_time = 0 self._device = device + self._friendly_name = friendly_name self._lock = Lock() @property @@ -202,7 +203,7 @@ class LocaltuyaCover(CoverEntity): # Serial numbers are unique identifiers within a specific domain ("LocalTuya", f"local_{self._device.unique_id}") }, - "name": self._device._device.friendly_name, + "name": self._device._friendly_name, "manufacturer": "Tuya generic", "model": "SmartCover", "sw_version": "3.3", diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 765261c..d43a168 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -63,7 +63,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): for device_config in entities_to_setup: lights.append( LocaltuyaLight( - TuyaCache(device), + TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]), device_config[CONF_FRIENDLY_NAME], device_config[CONF_ID], ) @@ -80,11 +80,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class TuyaCache: """Cache wrapper for pytuya.TuyaDevices""" - def __init__(self, device): + def __init__(self, device, friendly_name): """Initialize the cache.""" self._cached_status = "" self._cached_status_time = 0 self._device = device + self._friendly_name = friendly_name self._lock = Lock() @property @@ -147,6 +148,19 @@ class LocaltuyaLight(LightEntity): self._color_temp = 127 self._bulb_id = bulbid + @property + def device_info(self): + return { + "identifiers": { + # Serial numbers are unique identifiers within a specific domain + ("LocalTuya", f"local_{self._device.unique_id}") + }, + "name": self._device._friendly_name, + "manufacturer": "Tuya generic", + "model": "SmartLight", + "sw_version": "3.3", + } + def state(self): self._device.state() diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index b7468ae..58fc637 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -173,7 +173,7 @@ payload_dict = { class TuyaDevice(object): - def __init__(self, dev_id, address, local_key, friendly_name, name = "", connection_timeout=10): + def __init__(self, dev_id, address, local_key, connection_timeout=10): """ Represents a Tuya device. @@ -189,8 +189,6 @@ class TuyaDevice(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 288097b..898b99d 100644 --- a/custom_components/localtuya/strings.json +++ b/custom_components/localtuya/strings.json @@ -16,7 +16,6 @@ "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 696f7ea..41768c2 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -101,7 +101,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): for device_config in entities_to_setup: switches.append( LocaltuyaSwitch( - TuyaCache(device), + TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]), device_config[CONF_FRIENDLY_NAME], device_config[CONF_ID], device_config.get(CONF_CURRENT), @@ -121,11 +121,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class TuyaCache: """Cache wrapper for pytuya.TuyaDevice""" - def __init__(self, device): + def __init__(self, device, friendly_name): """Initialize the cache.""" self._cached_status = "" self._cached_status_time = 0 self._device = device + self._friendly_name = friendly_name self._lock = Lock() @property @@ -220,7 +221,7 @@ class LocaltuyaSwitch(SwitchEntity): # Serial numbers are unique identifiers within a specific domain ("LocalTuya", f"local_{self._device.unique_id}") }, - "name": self._device._device.friendly_name, + "name": self._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 002eaec..c0be82a 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -15,7 +15,6 @@ "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",