Skip to content

Commit

Permalink
Add firmware version checking (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu authored Feb 10, 2022
1 parent f54a5a5 commit 1f20d96
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python_scripts/shellies_discovery_gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ATTR_LIGHT = "light"
ATTR_MAC = "mac"
ATTR_MANUFACTURER = "Allterco Robotics"
ATTR_MIN_FIRMWARE_DATE = "min_firmware_date"
ATTR_MODEL = "model"
ATTR_NAME = "name"
ATTR_RELAY_BINARY_SENSORS = "relay_binary_sensors"
Expand Down Expand Up @@ -429,6 +430,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PLUS_1PM: {
ATTR_NAME: "Shelly Plus 1PM",
Expand Down Expand Up @@ -462,6 +464,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PLUS_2PM: {
ATTR_NAME: "Shelly Plus 2PM",
Expand Down Expand Up @@ -505,6 +508,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220205,
},
MODEL_PLUS_I4: {
ATTR_NAME: "Shelly Plus i4",
Expand All @@ -525,6 +529,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PRO_1: {
ATTR_NAME: "Shelly Pro 1",
Expand All @@ -548,6 +553,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PRO_1PM: {
ATTR_NAME: "Shelly Pro 1PM",
Expand Down Expand Up @@ -582,6 +588,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PRO_2: {
ATTR_NAME: "Shelly Pro 2",
Expand All @@ -605,6 +612,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PRO_2PM: {
ATTR_NAME: "Shelly Pro 2PM",
Expand Down Expand Up @@ -639,6 +647,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
MODEL_PRO_4PM: {
ATTR_NAME: "Shelly Pro 4PM",
Expand Down Expand Up @@ -674,6 +683,7 @@
SENSOR_WIFI_IP: DESCRIPTION_SENSOR_WIFI_IP,
SENSOR_WIFI_SIGNAL: DESCRIPTION_SENSOR_WIFI_SIGNAL,
},
ATTR_MIN_FIRMWARE_DATE: 20220117,
},
}

Expand Down Expand Up @@ -1093,6 +1103,18 @@ def configure_device():

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

min_firmware_date = SUPPORTED_MODELS[model][ATTR_MIN_FIRMWARE_DATE]
try:
firmware_date = int(firmware_id.split("-", 1)[0])
except ValueError:
raise ValueError(
f"firmware version {min_firmware_date} is not supported, update your device {device_id}"
)
if firmware_date < min_firmware_date:
raise ValueError(
f"firmware dated {min_firmware_date} is required, update your device {device_id}"
)

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

0 comments on commit 1f20d96

Please sign in to comment.