Skip to content

Commit

Permalink
Merge pull request #144 from AaronLionsheep/issue-142
Browse files Browse the repository at this point in the history
Populate the Indigo firmware column
  • Loading branch information
AaronLionsheep authored Oct 9, 2023
2 parents fd046b3 + 0201c1e commit eb698bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ShellyMQTT.indigoPlugin/Contents/Server Plugin/Devices/Shelly.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ def parseAnnouncement(self, payload):
self.device.updateStateOnServer('firmware-version', firmware_version)
self.device.updateStateOnServer('has-firmware-update', has_firmware_update)

if firmware_version:
# Populate the firmware UI column
cleaned_firmware_version: str = firmware_version
if "/" in cleaned_firmware_version:
# Remove the date part of the version string
cleaned_firmware_version = cleaned_firmware_version.split("/")[-1]
if cleaned_firmware_version[0] == "v":
# Remove the leading "v"
cleaned_firmware_version = cleaned_firmware_version[1:]
# Replace "@" with "-" for consistency
cleaned_firmware_version = cleaned_firmware_version.replace("@", "-")

pluginProps = self.device.pluginProps
pluginProps.update({"version": cleaned_firmware_version})
self.device.replacePluginPropsOnServer(pluginProps)

def processInputEvent(self, eventMessage):
"""
Parses an input event message and fires triggers if this is a new input event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ def test_parseAnnouncement_invalid_announcement_for_device(self):
self.assertEqual("3", self.device.states['firmware-version'])
self.assertFalse(self.device.states['has-firmware-update'])

def test_parseAnnouncement_formats_version_for_display(self):
self.device.pluginProps['address'] = "shellies/test-shelly"
self.shelly.parseAnnouncement('{"id": "test-shelly", "fw_ver": "20221027-100516/1.12.1-ga9117d3"}')
self.assertEqual(self.device.pluginProps["version"], "1.12.1-ga9117d3")
self.shelly.parseAnnouncement('{"id": "test-shelly", "fw_ver": "20221027-100516/v1.12.1-ga9117d3"}')
self.assertEqual(self.device.pluginProps["version"], "1.12.1-ga9117d3")
self.shelly.parseAnnouncement('{"id": "test-shelly", "fw_ver": "20220620-083944/v2.1.6@166b8318+"}')
self.assertEqual(self.device.pluginProps["version"], "2.1.6-166b8318+")

def test_updateEnergy_4_decimals(self):
self.shelly.updateEnergy(50)
self.assertAlmostEqual(0.0008, self.shelly.device.states['accumEnergyTotal'], 4)
Expand Down

0 comments on commit eb698bb

Please sign in to comment.