Skip to content

Commit

Permalink
Fix local Z2M provider (zigpy#1447)
Browse files Browse the repository at this point in the history
Ensure local Z2M provider works
  • Loading branch information
puddly authored Aug 14, 2024
1 parent 33680a0 commit 284642e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tests/ota/test_ota_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ async def test_ota_config_invalid_provider(tmp_path: pathlib.Path) -> None:

async def test_ota_config_complex(tmp_path: pathlib.Path) -> None:
# Enable all the providers
(tmp_path / "index.json").write_text("{}")

ota = zigpy.ota.OTA(
config=config.SCHEMA_OTA(
{
Expand Down Expand Up @@ -187,6 +189,14 @@ async def test_ota_config_complex(tmp_path: pathlib.Path) -> None:
config.CONF_OTA_PROVIDER_PATH: tmp_path,
config.CONF_OTA_PROVIDER_WARNING: config.CONF_OTA_ALLOW_ADVANCED_DIR_STRING,
},
{
config.CONF_OTA_PROVIDER_TYPE: "z2m_local",
config.CONF_OTA_PROVIDER_INDEX_FILE: tmp_path / "index.json",
},
{
config.CONF_OTA_PROVIDER_TYPE: "zigpy_local",
config.CONF_OTA_PROVIDER_INDEX_FILE: tmp_path / "index.json",
},
],
}
),
Expand All @@ -204,6 +214,8 @@ async def test_ota_config_complex(tmp_path: pathlib.Path) -> None:
manufacturer_ids=[0xABCD, 0xDCBA],
),
zigpy.ota.providers.AdvancedFileProvider(path=tmp_path),
zigpy.ota.providers.LocalZ2MProvider(index_file=tmp_path / "index.json"),
zigpy.ota.providers.LocalZigpyProvider(index_file=tmp_path / "index.json"),
]


Expand Down
5 changes: 3 additions & 2 deletions zigpy/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
CONF_OTA_PROVIDER_TYPE = "type"
CONF_OTA_PROVIDER_URL = "url"
CONF_OTA_PROVIDER_PATH = "path"
CONF_OTA_PROVIDER_INDEX_FILE = "index_file"
CONF_OTA_PROVIDER_OVERRIDE_PREVIOUS = "override_previous"
CONF_OTA_PROVIDER_WARNING = "warning"
CONF_OTA_BROADCAST_ENABLED = "broadcast_enabled"
Expand Down Expand Up @@ -170,7 +171,7 @@
)

SCHEMA_OTA_PROVIDER_JSON_INDEX = SCHEMA_OTA_PROVIDER_BASE.extend(
{vol.Required(CONF_OTA_PROVIDER_PATH): cv_json_file}
{vol.Required(CONF_OTA_PROVIDER_INDEX_FILE): cv_json_file}
)

SCHEMA_OTA_PROVIDER_FOLDER = SCHEMA_OTA_PROVIDER_BASE.extend(
Expand Down Expand Up @@ -281,7 +282,7 @@
cv_deprecated(
"The `z2m_local_index` key is deprecated, migrate your configuration"
" to the `extra_providers` list instead: `extra_providers: [{'type': 'z2m_local',"
" 'path': '/path/to/index.json'}]`"
" 'index_file': '/path/to/index.json'}]`"
),
cv_json_file,
),
Expand Down
3 changes: 1 addition & 2 deletions zigpy/ota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import contextlib
import dataclasses
import logging
import pathlib
import sys
import typing

Expand Down Expand Up @@ -322,7 +321,7 @@ def register_deprecated_provider(
config={"path": config.get(CONF_OTA_ADVANCED_DIR)},
)
register_deprecated_provider(
enabled=isinstance(config.get(CONF_OTA_Z2M_LOCAL_INDEX), pathlib.Path),
enabled=None if config.get(CONF_OTA_Z2M_LOCAL_INDEX) is None else True,
provider=zigpy.ota.providers.LocalZ2MProvider,
config={"index_file": config.get(CONF_OTA_Z2M_LOCAL_INDEX)},
)
Expand Down

0 comments on commit 284642e

Please # to comment.