Просмотр исходного кода

Clean up config and docs after removal of deprecated entities.

- update dependencies to latest.
Jason Rumney 3 лет назад
Родитель
Сommit
5922563351

+ 7 - 25
README.md

@@ -260,10 +260,6 @@ The final stage is to choose a name for the device in Home Assistant.
 If you have multiple devices of the same type, you may want to change
 the name to make it easier to distinguish them.
 
-Besides the name, usually you will want to accept the defaults at this
-step, as any checkboxes are for backwards compatibility deprecated entities
-that will be removed in future, alternatives should be available.
-
 #### name
 
     _(string) (Required)_ Any unique name for the
@@ -285,9 +281,15 @@ setting up a new device.  They are only retained for users who set up the
 device before support was added for the actual entity matching the device,
 or when a function was misunderstood, and will not be retained forever.
 
+As of 0.18.0, there are no longer any deprecated entities, but they
+may be reintroduced in future if better representations of existing
+devices emerge again.
+
 ## Offline operation gotchas
 
-Many Tuya devices will stop responding if unable to connect to the Tuya servers for an extended period.  Reportedly, some devices act better offline if DNS as well as TCP connections is blocked.
+Many Tuya devices will stop responding if unable to connect to the
+Tuya servers for an extended period.  Reportedly, some devices act
+better offline if DNS as well as TCP connections is blocked.
 
 
 ## Heater gotchas
@@ -335,13 +337,6 @@ presets work, please leave feedback in Issue #19.
 
 ## Fan gotchas
 
-Fans should be configured as `fan` entities, with any auxilary
-functions such as panel lighting control, child locks or additional
-switches configured as `light`, `lock` or `switch` entities.
-Configuration of Goldair fans as `climate` entities is supported for
-backward compatibility but is deprecated, and may be removed in
-future.
-
 Reportedly, Goldair fans can be a bit flaky. If they become
 unresponsive, give them about 60 seconds to wake up again.
 
@@ -393,19 +388,6 @@ only have one output.  The HVAC mode is provided as an indicator of which
 mode they are in, but are set to readonly so that you cannot accidentally
 switch the thermostat to the wrong mode from HA.
 
-## Humidifiers and dehumidifiers
-
-Humidifiers and Dehumidifiers should be configuured as `humidifier`
-entities, probably with `fan` entities as well if the fan speed can
-also be controlled, and any other auxilary features such as panel
-lighting, child locks or additional switches configured as `light`,
-`lock` or `switch` entities.  Configration of Goldair Dehumidifiers
-and Eanons Humidifiers as `climate` entities is also supported for
-backwards compatibility, but is deprecated and may be removed in
-future.  In particular, when humidifiers are represented as `climate`
-entities, the running mode will show as `Dry`, as the climate entity
-only supports functions commonly found on air conditioners/heatpumps.
-
 
 ## Finding your device ID and local key
 

+ 13 - 0
custom_components/tuya_local/__init__.py

@@ -199,6 +199,19 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
                 opts.pop(e.config_id, None)
         entry.options = {**opts}
         entry.version = 8
+    if entry.version == 8:
+        # Deprecated entities are removed, trim the config back to required
+        # config only
+        conf = {**entry.data, **entry.options}
+        entry.data = {
+            CONF_DEVICE_ID: conf[CONF_DEVICE_ID],
+            CONF_LOCAL_KEY: conf[CONF_LOCAL_KEY],
+            CONF_HOST: conf[CONF_HOST],
+            CONF_TYPE: conf[CONF_TYPE],
+        }
+        entry.options = {}
+        entry.version = 9
+
     return True
 
 

+ 2 - 17
custom_components/tuya_local/config_flow.py

@@ -14,7 +14,7 @@ _LOGGER = logging.getLogger(__name__)
 
 
 class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
-    VERSION = 8
+    VERSION = 9
     CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
     device = None
     data = {}
@@ -96,12 +96,6 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
             )
         config = get_config(self.data[CONF_TYPE])
         schema = {vol.Required(CONF_NAME, default=config.name): str}
-        e = config.primary_entity
-        if e.deprecated:
-            schema[vol.Optional(e.config_id, default=False)] = bool
-        for e in config.secondary_entities():
-            if e.deprecated:
-                schema[vol.Optional(e.config_id, default=False)] = bool
 
         return self.async_show_form(
             step_id="choose_entities",
@@ -142,16 +136,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
         cfg = get_config(config[CONF_TYPE])
         if cfg is None:
             return self.async_abort(reason="not_supported")
-        e = cfg.primary_entity
-        if e.deprecated:
-            schema[
-                vol.Optional(e.config_id, default=config.get(e.config_id, True))
-            ] = bool
-        for e in cfg.secondary_entities():
-            if e.deprecated:
-                schema[
-                    vol.Optional(e.config_id, default=config.get(e.config_id, False))
-                ] = bool
+
         return self.async_show_form(
             step_id="user",
             data_schema=vol.Schema(schema),

+ 1 - 1
custom_components/tuya_local/manifest.json

@@ -7,6 +7,6 @@
     "issue_tracker": "https://github.com/make-all/tuya-local/issues",
     "dependencies": [],
     "codeowners": ["@make-all"],
-    "requirements": ["pycryptodome~=3.14.1","tinytuya~=1.6.1"],
+    "requirements": ["pycryptodome~=3.15.0","tinytuya~=1.6.4"],
     "config_flow": true
 }

+ 1 - 1
requirements-dev.txt

@@ -5,4 +5,4 @@ pytest
 pytest-asyncio
 pytest-cov
 pycryptodome~=3.15.0
-tinytuya~=1.6.1
+tinytuya~=1.6.4

+ 1 - 1
requirements.txt

@@ -1,2 +1,2 @@
 pycryptodome~=3.15.0
-tinytuya~=1.6.1
+tinytuya~=1.6.4

+ 7 - 27
tests/test_config_flow.py

@@ -45,7 +45,7 @@ async def test_init_entry(hass):
     """Test initialisation of the config flow."""
     entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         title="test",
         data={
             CONF_DEVICE_ID: "deviceid",
@@ -430,7 +430,7 @@ async def test_flow_choose_entities_creates_config_entry(hass, bypass_setup):
             },
         )
         expected = {
-            "version": 8,
+            "version": 9,
             "type": "create_entry",
             "flow_id": ANY,
             "handler": DOMAIN,
@@ -453,7 +453,7 @@ async def test_options_flow_init(hass):
     """Test config flow options."""
     config_entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         unique_id="uniqueid",
         data={
             CONF_DEVICE_ID: "deviceid",
@@ -488,7 +488,7 @@ async def test_options_flow_modifies_config(mock_test, hass):
 
     config_entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         unique_id="uniqueid",
         data={
             CONF_DEVICE_ID: "deviceid",
@@ -528,7 +528,7 @@ async def test_options_flow_fails_when_connection_fails(mock_test, hass):
 
     config_entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         unique_id="uniqueid",
         data={
             CONF_DEVICE_ID: "deviceid",
@@ -564,7 +564,7 @@ async def test_options_flow_fails_when_config_is_missing(mock_test, hass):
 
     config_entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         unique_id="uniqueid",
         data={
             CONF_DEVICE_ID: "deviceid",
@@ -584,32 +584,12 @@ async def test_options_flow_fails_when_config_is_missing(mock_test, hass):
     assert result["reason"] == "not_supported"
 
 
-# More tests to exercise code branches that earlier tests missed.
-@patch("custom_components.tuya_local.setup_device")
-async def test_async_setup_entry_for_dehumidifier(mock_setup, hass):
-    """Test setting up based on a config entry.  Repeats test_init_entry."""
-    config_entry = MockConfigEntry(
-        domain=DOMAIN,
-        version=8,
-        unique_id="uniqueid",
-        data={
-            CONF_CLIMATE: False,
-            CONF_DEVICE_ID: "deviceid",
-            CONF_HOST: "hostname",
-            CONF_LOCAL_KEY: "localkey",
-            CONF_NAME: "test",
-            CONF_TYPE: "goldair_dehumidifier",
-        },
-    )
-    assert await async_setup_entry(hass, config_entry)
-
-
 @patch("custom_components.tuya_local.setup_device")
 async def test_async_setup_entry_for_switch(mock_device, hass):
     """Test setting up based on a config entry.  Repeats test_init_entry."""
     config_entry = MockConfigEntry(
         domain=DOMAIN,
-        version=8,
+        version=9,
         unique_id="uniqueid",
         data={
             CONF_DEVICE_ID: "deviceid",