Skip to content

Commit

Permalink
Improve min firmware check (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu authored Mar 26, 2022
1 parent 3a5749c commit 64f4f59
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions python_scripts/shellies_discovery_gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,33 +1090,17 @@ def configure_device():


device_id = data[ATTR_ID] # noqa: F821
device_config = data["device_config"] # noqa: F821
firmware_id = device_config["sys"]["device"][ATTR_FW_ID]
mac = device_config["sys"]["device"][ATTR_MAC]
device_name = device_config["sys"]["device"][ATTR_NAME]
device_url = f"http://{device_config['mqtt']['topic_prefix']}.local/"
default_topic = f"{device_config['mqtt']['topic_prefix']}/"
if device_id is None:
raise ValueError("id value None is not valid, check script configuration")

model = device_id.rsplit("-", 1)[0]

if model not in SUPPORTED_MODELS:
raise ValueError(
f"model {model} is not supported, please open an issue here https://github.com/bieniu/ha-shellies-discovery-gen2/issues"
)

if not device_name:
device_name = SUPPORTED_MODELS[model][ATTR_NAME]

if device_id is None:
raise ValueError("id value None is not valid, check script configuration")
if mac is None:
raise ValueError("mac value None is not valid, check script configuration")

qos = data.get(CONF_QOS, 0) # noqa: F821
if qos not in (0, 1, 2):
raise ValueError(f"QoS value {qos} is not valid, check script configuration")

disc_prefix = data.get(CONF_DISCOVERY_PREFIX, DEFAULT_DISC_PREFIX) # noqa: F821
device_config = data["device_config"] # noqa: F821
firmware_id = device_config["sys"]["device"][ATTR_FW_ID]

min_firmware_date = SUPPORTED_MODELS[model][ATTR_MIN_FIRMWARE_DATE]
try:
Expand All @@ -1130,6 +1114,23 @@ def configure_device():
f"firmware dated {min_firmware_date} is required, update your device {device_id}"
)

mac = device_config["sys"]["device"][ATTR_MAC]
if mac is None:
raise ValueError("mac value None is not valid, check script configuration")

device_name = device_config["sys"]["device"][ATTR_NAME]
device_url = f"http://{device_config['mqtt']['topic_prefix']}.local/"
default_topic = f"{device_config['mqtt']['topic_prefix']}/"

if not device_name:
device_name = SUPPORTED_MODELS[model][ATTR_NAME]

qos = data.get(CONF_QOS, 0) # noqa: F821
if qos not in (0, 1, 2):
raise ValueError(f"QoS value {qos} is not valid, check script configuration")

disc_prefix = data.get(CONF_DISCOVERY_PREFIX, DEFAULT_DISC_PREFIX) # noqa: F821

device_info = {
KEY_CONNECTIONS: [[KEY_MAC, format_mac(mac)]],
KEY_NAME: device_name,
Expand Down

0 comments on commit 64f4f59

Please sign in to comment.