First working implementation of Devices

This commit is contained in:
rospogrigio
2020-09-11 14:48:49 +02:00
parent 9a45eb8398
commit c008339f43
8 changed files with 36 additions and 15 deletions

View File

@@ -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],

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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'

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",