Skip to content

Commit

Permalink
Merge branch 'SmartThingsCommunity:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhmachenkov authored Feb 19, 2023
2 parents 8f119c9 + 0c57d6f commit aff4c75
Show file tree
Hide file tree
Showing 82 changed files with 484 additions and 118 deletions.
70 changes: 41 additions & 29 deletions .github/scripts/check_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,40 @@ def compare_embedded_configs(cap1, cap2):
# no mismatches found
return True

def compare_preferences(prof1, prof2):
if "preferences" in prof1 and "preferences" in prof2:
return prof1["preferences"] == prof2["preferences"]
elif "preferences" not in prof1 and "preferences" not in prof2:
return True
else:
return False

def compare_components(prof1, prof2):
if len(prof1["components"]) == len(prof2["components"]):
for y, new_component in enumerate(prof1["components"]):
current_component = prof2["components"][y]

# compare categores. Use get() in case the category does not exist like in "thing" profiles
if new_component.get("categories") != current_component.get("categories"):
return False

# check that there are the same number of capabilities and that the top capability matches
if ((len(new_component["capabilities"]) == len(current_component["capabilities"])) and
(new_component["capabilities"][0]["id"] == current_component["capabilities"][0]["id"])):
# check if capabilities are the exact same, or
# similar with same top capability but different subsequent ordering
if (new_component["capabilities"] == current_component["capabilities"] or
compare_component_capabilities_unordered(new_component, current_component)):
print("Duplicate capabilties found.")
else:
return False
else:
return False
else:
return False

return True

with open(str(Path.home()) + '/files.csv', 'r') as csvfile:
csvreader = csv.reader(csvfile)
changed_files = next(csvreader)
Expand All @@ -72,45 +106,20 @@ def compare_embedded_configs(cap1, cap2):
# compare to YAML files that are not the same file
# Compare only .yml files and only files that have not already been found to be a duplicate
if current_profile != new_profile and Path(current_profile).suffix == ".yml" and (current_profile, new_profile) not in duplicate_pairs:
is_duplicate = True
print("Comparing %s vs %s" % (new_profile, current_profile))
with open(new_profile) as new_data, open(current_profile) as current_data:
new_profile_map = yaml.safe_load(new_data)
current_profile_map = yaml.safe_load(current_data)

''' Compare components. A duplicate is defined as follows:
''' Compare profiles. A duplicate is defined as follows:
- categories must be the same
- capabilities must be the same, with some ordering restrictions
- top capability must match, but subsequent ordering does not matter
- embedded configs must be the same, but certain values can be ordered differently (i.e. enabledValues)
- preferences must be the same
'''
if len(new_profile_map["components"]) == len(current_profile_map["components"]):
for y, new_component in enumerate(new_profile_map["components"]):
current_component = current_profile_map["components"][y]

# compare categores. Use get() in case the category does not exist like in "thing" profiles
if new_component.get("categories") != current_component.get("categories"):
is_duplicate = False
break

# check that there are the same number of capabilities and that the top capability matches
if ((len(new_component["capabilities"]) == len(current_component["capabilities"])) and
(new_component["capabilities"][0]["id"] == current_component["capabilities"][0]["id"])):
# check if capabilities are the exact same, or
# similar with same top capability but different subsequent ordering
if (new_component["capabilities"] == current_component["capabilities"] or
compare_component_capabilities_unordered(new_component, current_component)):
print("Duplicate capabilties found.")
else:
is_duplicate = False
break
else:
is_duplicate = False
break
else:
is_duplicate = False

if is_duplicate:
if(compare_preferences(new_profile_map, current_profile_map) == True and
compare_components(new_profile_map, current_profile_map) == True):
print("%s and %s are duplicates!\n" % (new_profile, current_profile))
duplicate_pairs.append((new_profile, current_profile))

Expand All @@ -124,3 +133,6 @@ def compare_embedded_configs(cap1, cap2):
f.write("%s == %s\n" % (duplicate[0], duplicate [1]))
else:
f.write("Duplicate profile check: Passed - no duplicate profiles detected.")

with open("profile-comment-body.md", "r") as f:
print("\n" + f.read())
34 changes: 34 additions & 0 deletions .github/workflows/duplicate-profiles-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Post duplicate profile comment
on:
workflow_run:
workflows: [Check for duplicate profiles]
types:
- completed

jobs:
comment-on-pr:
runs-on: ubuntu-latest
steps:
- name: Download comment artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: duplicate-profiles.yml
run_id: ${{ github.event.workflow_run.id }}

- run: echo "pr_number=$(cat pr_number/pr_number.txt)" >> $GITHUB_ENV

- name: Find comment
uses: peter-evans/find-comment@v2
id: fc
with:
body-includes: Duplicate profile check
comment-author: 'github-actions[bot]'
issue-number: ${{ env.pr_number }}

- name: Post comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-file: 'duplicate_profile_comment/profile-comment-body.md'
edit-mode: replace
issue-number: ${{ env.pr_number }}
25 changes: 12 additions & 13 deletions .github/workflows/duplicate-profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ jobs:
run: |
python ./.github/scripts/check_duplicates.py
- name: Find comment
uses: peter-evans/find-comment@v2
id: fc
- name: Upload duplicate profile comment artifact
uses: actions/upload-artifact@v3
with:
body-includes: Duplicate profile check
comment-author: 'github-actions[bot]'
issue-number: ${{ github.event.number }}
name: duplicate_profile_comment
path: |
profile-comment-body.md
- name: Post comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-file: 'profile-comment-body.md'
edit-mode: replace
issue-number: ${{ github.event.number }}
- run: echo ${{ github.event.number }} > pr_number.txt

- name: Upload PR info
uses: actions/upload-artifact@v3
with:
name: pr_number
path: |
pr_number.txt
39 changes: 22 additions & 17 deletions drivers/SmartThings/bose/src/disco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,32 @@ function Disco.find(deviceid, callback)
local val, rip, _ = s:receivefrom()
if val then
local headers = process_response(val)
local ip, port, id = headers["location"]:match(
"http://([^,/]+):([^/]+)/%a+/BO5EBO5E%-F00D%-F00D%-FEED%-([%g-]+).xml")
if headers["location"] ~= nil then
local ip, port, id = headers["location"]:match(
"http://([^,/]+):([^/]+)/%a+/BO5EBO5E%-F00D%-F00D%-FEED%-([%g-]+).xml")

-- TODO how do I know the device that responded is actually a bose device
-- potentially will need to make a request to the endpoint
-- fetch_device_metadata()
if rip ~= ip then
log.warn(string.format(
"[%s]recieved discovery response with reported (%s) & source IP (%s) mismatch, ignoring",
deviceid, rip, ip))
log.debug(rip, "!=", ip)
elseif ip and id then
if deviceid then
-- check if the speaker we just found was the one we were looking for
if deviceid == id then
-- TODO how do I know the device that responded is actually a bose device
-- potentially will need to make a request to the endpoint
-- fetch_device_metadata()
if rip ~= ip then
log.warn(string.format(
"[%s]recieved discovery response with reported (%s) & source IP (%s) mismatch, ignoring",
deviceid, rip, ip))
log.debug(rip, "!=", ip)
elseif ip and id then
if deviceid then
-- check if the speaker we just found was the one we were looking for
if deviceid == id then
callback({id = id, ip = ip, raw = val})
break
end
else
callback({id = id, ip = ip, raw = val})
break
end
else
callback({id = id, ip = ip, raw = val})
end
else
log.error_with({hub_logs = true},
string.format("disco response received from %s doesn't contain location header: %s", rip, val))
end
elseif rip == "timeout" then
if deviceid then
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-lock/profiles/base-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ components:
version: 1
- id: tamperAlert
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-media/profiles/media-speaker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ components:
version: 1
- id: audioMute
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ components:
version: 1
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ components:
version: 1
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/contact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ components:
capabilities:
- id: contactSensor
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: HumiditySensor
preferences:
- preferenceId: humidityOffset
explicit: true
5 changes: 5 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/humidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ components:
capabilities:
- id: relativeHumidityMeasurement
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: HumiditySensor
preferences:
- preferenceId: humidityOffset
explicit: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/illuminance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ components:
capabilities:
- id: illuminanceMeasurement
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ components:
version: 1
- id: illuminanceMeasurement
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/motion-battery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/motion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ components:
capabilities:
- id: motionSensor
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 2 additions & 0 deletions drivers/SmartThings/matter-sensor/profiles/sensor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: GenericSensor
preferences:
- preferenceId: tempOffset
explicit: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ components:
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: GenericSensor
preferences:
- preferenceId: tempOffset
explicit: true
- preferenceId: humidityOffset
explicit: true
Loading

0 comments on commit aff4c75

Please sign in to comment.