Skip to content

Commit

Permalink
Support for manufacturer/ model & startup bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timlaing committed Jun 30, 2023
1 parent ffe2e79 commit fa19d74
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 179 deletions.
2 changes: 1 addition & 1 deletion custom_components/tuya_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
get_device_id(entry.data),
)
config = {**entry.data, **entry.options, "name": entry.title}
setup_device(hass, config)
await setup_device(hass, config)
device_conf = get_config(entry.data[CONF_TYPE])
if device_conf is None:
_LOGGER.error(NOT_FOUND, config[CONF_TYPE])
Expand Down
4 changes: 4 additions & 0 deletions custom_components/tuya_local/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ async def async_step_user(self, user_input=None):
errors["base"] = "connection"

schema = {
vol.Required(
CONF_DEVICE_ID,
default=config.get(CONF_DEVICE_ID, ""),
): str,
vol.Required(
CONF_LOCAL_KEY,
default=config.get(CONF_LOCAL_KEY, ""),
Expand Down
26 changes: 18 additions & 8 deletions custom_components/tuya_local/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo


from .const import (
API_PROTOCOL_VERSIONS,
CONF_DEVICE_ID,
CONF_LOCAL_KEY,
CONF_POLL_ONLY,
CONF_TYPE,
CONF_PROTOCOL_VERSION,
DOMAIN,
CONF_DEVICE_CID,
)
from .helpers.config import get_device_id
from .helpers.device_config import possible_matches
from .helpers.device_config import possible_matches, get_config, TuyaDeviceConfig
from .helpers.log import log_json


Expand All @@ -44,6 +47,7 @@ def __init__(
protocol_version,
dev_cid,
hass: HomeAssistant,
config: TuyaDeviceConfig,
poll_only=False,
):
"""
Expand All @@ -67,6 +71,7 @@ def __init__(
self._api_protocol_version_index = None
self._api_protocol_working = False
self._api_working_protocol_failures = 0
self._config = config
try:
if dev_cid is not None:
self._api = tinytuya.Device(
Expand Down Expand Up @@ -128,18 +133,22 @@ def unique_id(self):
@property
def device_info(self):
"""Return the device information for this device."""
return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": self.name,
"manufacturer": "Tuya",
}
device_info = DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
name=self.name,
default_manufacturer="Tuya",
manufacturer = self._config.manufacturer,
model = self._config.model,
)

return device_info

@property
def has_returned_state(self):
"""Return True if the device has returned some state."""
return len(self._get_cached_state()) > 1

def actually_start(self, event=None):
async def actually_start(self, event=None):
_LOGGER.debug("Starting monitor loop for %s", self.name)
self._running = True
self._shutdown_listener = self._hass.bus.async_listen_once(
Expand Down Expand Up @@ -605,7 +614,7 @@ def get_key_for_value(obj, value, fallback=None):
return keys[values.index(value)] if value in values else fallback


def setup_device(hass: HomeAssistant, config: dict):
async def setup_device(hass: HomeAssistant, config: dict):
"""Setup a tuya device based on passed in config."""

_LOGGER.info("Creating device: %s", get_device_id(config))
Expand All @@ -618,6 +627,7 @@ def setup_device(hass: HomeAssistant, config: dict):
config[CONF_PROTOCOL_VERSION],
config.get(CONF_DEVICE_CID),
hass,
get_config(config[CONF_TYPE]),
config[CONF_POLL_ONLY],
)
hass.data[DOMAIN][get_device_id(config)] = {"device": device}
Expand Down
Loading

0 comments on commit fa19d74

Please sign in to comment.