From 9a45eb8398045f5286f7a22553fdecd2791302bb Mon Sep 17 00:00:00 2001 From: rospogrigio Date: Fri, 11 Sep 2020 11:55:43 +0200 Subject: [PATCH] Fixed conflicts --- custom_components/localtuya/__init__.py | 3 +++ custom_components/localtuya/config_flow.py | 3 ++- custom_components/localtuya/switch.py | 23 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index f3c215a..a00b436 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -17,6 +17,9 @@ async def async_setup(hass: HomeAssistant, config: dict): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up LocalTuya integration from a config entry.""" + + print('async_setup_entry localtuya subswitch [{}] '.format(entry.data)) + for component in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component) diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index 6d814ef..b86b9a3 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -180,8 +180,9 @@ 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_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/switch.py b/custom_components/localtuya/switch.py index 9b2ae03..36aeb54 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -103,6 +103,10 @@ DPS_FIELDS = [ async def async_setup_entry(hass, config_entry, async_add_entities): """Setup a Tuya switch based on a config entry.""" + + print('config_entry: [{}] '.format(config_entry.data)) + + switches_to_setup = [ entity for entity in config_entry.data[CONF_ENTITIES] @@ -120,9 +124,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): pytuyadevice.set_version(float(config_entry.data[CONF_PROTOCOL_VERSION])) pytuyadevice.set_dpsUsed({}) + print('switches_to_setup: [{}] '.format(switches_to_setup)) + for device_config in switches_to_setup: switches.append( - TuyaDevice( + LocaltuyaSwitch( TuyaCache(pytuyadevice), device_config[CONF_FRIENDLY_NAME], device_config[CONF_ID], @@ -213,6 +219,7 @@ class TuyaCache: finally: self._lock.release() + class LocaltuyaSwitch(SwitchEntity): """Representation of a Tuya switch.""" @@ -241,6 +248,20 @@ 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) + }, + "name": "MyName", + "manufacturer": "Tuya generic", + "model": "SmartSwitch", + "sw_version": "3.3", + } + @property def name(self): """Get name of Tuya switch."""