Merge branch 'physical_device'
This commit is contained in:
@@ -73,7 +73,9 @@ def strip_dps_values(user_input, dps_strings):
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
"""Validate the user input allows us to connect."""
|
||||
pytuyadevice = pytuya.TuyaDevice(
|
||||
data[CONF_DEVICE_ID], data[CONF_HOST], data[CONF_LOCAL_KEY]
|
||||
data[CONF_DEVICE_ID],
|
||||
data[CONF_HOST],
|
||||
data[CONF_LOCAL_KEY],
|
||||
)
|
||||
pytuyadevice.set_version(float(data[CONF_PROTOCOL_VERSION]))
|
||||
pytuyadevice.set_dpsUsed({})
|
||||
@@ -186,8 +188,10 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
else:
|
||||
self.entities.append(_convert_entity(user_input))
|
||||
|
||||
#print('ENTITIES: [{}] '.format(self.entities))
|
||||
config = {
|
||||
CONF_NAME: f"{user_input[CONF_DEVICE_ID]} (import from configuration.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],
|
||||
|
@@ -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
|
||||
@@ -195,6 +196,24 @@ class LocaltuyaCover(CoverEntity):
|
||||
)
|
||||
)
|
||||
|
||||
@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": "SmartCover",
|
||||
"sw_version": "3.3",
|
||||
}
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique device identifier."""
|
||||
return f"local_{self._device.unique_id}_{self._switch_id}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Get name of Tuya switch."""
|
||||
@@ -215,11 +234,6 @@ class LocaltuyaCover(CoverEntity):
|
||||
"""Get name of stop command."""
|
||||
return self._stop_cmd
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique device identifier."""
|
||||
return f"local_{self._device.unique_id}"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if device is available or not."""
|
||||
|
@@ -54,6 +54,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
return
|
||||
|
||||
fans = []
|
||||
|
||||
for device_config in entities_to_setup:
|
||||
fans.append(
|
||||
LocaltuyaFan(
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -171,8 +171,9 @@ payload_dict = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TuyaDevice(object):
|
||||
def __init__(self, dev_id, address, local_key=None, connection_timeout=10):
|
||||
def __init__(self, dev_id, address, local_key, connection_timeout=10):
|
||||
"""
|
||||
Represents a Tuya device.
|
||||
|
||||
|
@@ -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
|
||||
@@ -184,6 +185,7 @@ class TuyaCache:
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
|
||||
class LocaltuyaSwitch(SwitchEntity):
|
||||
"""Representation of a Tuya switch."""
|
||||
|
||||
@@ -212,6 +214,19 @@ class LocaltuyaSwitch(SwitchEntity):
|
||||
)
|
||||
)
|
||||
|
||||
@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": "SmartSwitch",
|
||||
"sw_version": "3.3",
|
||||
}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Get name of Tuya switch."""
|
||||
|
Reference in New Issue
Block a user