Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandblue authored Jan 15, 2025
2 parents 0f7f354 + ad6cc1c commit 030e6ad
Show file tree
Hide file tree
Showing 144 changed files with 4,124 additions and 901 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create-channel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
head_ref: ${{ steps.head_ref.outputs.head_ref }}
steps:
- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
workflow: upload-driver-packages.yml
run_id: ${{ github.event.workflow_run.id }}
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
driver: ${{ fromJSON(needs.download-artifacts.outputs.drivers) }}
steps:
- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
workflow: upload-driver-packages.yml
name: ${{ matrix.driver }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/duplicate-profiles-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download comment artifact
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
workflow: duplicate-profiles.yml
run_id: ${{ github.event.workflow_run.id }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/duplicate-profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python ./.github/scripts/check_duplicates.py
- name: Upload duplicate profile comment artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: duplicate_profile_comment
path: |
Expand All @@ -40,7 +40,7 @@ jobs:
- run: echo ${{ github.event.number }} > pr_number.txt

- name: Upload PR info
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pr_number
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
workflow: run-tests.yml
run_id: ${{ github.event.workflow_run.id }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ jobs:
LUA_PATH: ${{ steps.lua_path.outputs.lua_path }}
- name: Upload test artifact
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: tests
path: |
tools/test_output/*.xml
- name: Upload coverage artifact
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage
path: |
Expand All @@ -156,13 +156,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Upload event file artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: event-file
path: ${{ github.event_path }}
- run: echo ${{ github.event.number }} > pr_number.txt
- name: Upload pr number artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pr_number
path: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/upload-driver-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
zip -v ${{env.package_key}}.zip config.yml fingerprints.yml search-parameters.y*ml $(find . -name "*.pem") $(find . -name "*.crt") $(find profiles -name "*.y*ml") $(find . -name "*.lua") -x "*test*"
- name: Upload packaged driver artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.package_key }}
path: |
Expand All @@ -51,14 +51,14 @@ jobs:
steps:
- run: echo ${{ github.event.number }} > pr_number.txt
- name: Upload pr number artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pr_number
path: |
pr_number.txt
- run: echo ${{ github.head_ref }} > head_ref.txt
- name: Upload head ref artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: head_ref
path: |
Expand Down
65 changes: 39 additions & 26 deletions drivers/Aqara/aqara-lock/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ local function device_init(self, device)
LockAlarm.supportedAlarmValues(SUPPORTED_ALARM_VALUES, { visibility = { displayed = false } })
)
end
device:emit_event(capabilities.lock.supportedUnlockDirections({"fromInside", "fromOutside"}, {visibility = {displayed = false}}))
device:emit_event(capabilities.battery.type("AA"))
device:emit_event(capabilities.battery.quantity(8))
end

local function device_added(self, device)
Expand Down Expand Up @@ -107,23 +110,33 @@ local function event_lock_handler(driver, device, evt_name, evt_value)
end
end

local function event_unlock_handler(driver, device, evt_name, evt_value)
local id, label
if evt_name == METHOD.RF447 then
evt_name = nil
id = nil
label = nil
elseif evt_name == METHOD.BLUETOOTH and evt_value == 2 then
evt_name = nil
id = nil
label = nil
elseif evt_value == 0x80020000 then -- one-time password
id = "OTP_STANDALONE"
label = nil
else
id, label = credential_utils.find_userLabel(driver, device, evt_value)
end
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = id, codeName = label } }))
local function event_unlock_indoor_handler(driver, device, evt_name, evt_value)
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = nil, codeName = nil, unlockDirection = "fromInside" } }))
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
device:emit_event(LockAlarm.alarm.clear({ visibility = { displayed = false }}))
end

local function event_unlock_outdoor_handler(driver, device, evt_name, evt_value)
local id, label = credential_utils.find_userLabel(driver, device, evt_value)
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = id, codeName = label, unlockDirection = "fromOutside" } }))
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
device:emit_event(LockAlarm.alarm.clear({ visibility = { displayed = false }}))
end

local function event_unlock_rf447_handler(driver, device, evt_name, evt_value)
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = nil, codeName = nil, unlockDirection = nil } }))
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
device:emit_event(LockAlarm.alarm.clear({ visibility = { displayed = false }}))
end

local function event_unlock_remote_handler(driver, device, evt_name, evt_value)
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = nil, codeName = nil, unlockDirection = nil } }))
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
device:emit_event(LockAlarm.alarm.clear({ visibility = { displayed = false }}))
end

local function event_unlock_otp_handler(driver, device, evt_name, evt_value)
device:emit_event(Lock.lock.unlocked({ data = { method = evt_name, codeId = "OTP_STANDALONE", codeName = nil, unlockDirection = "fromOutside" } }))
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
device:emit_event(LockAlarm.alarm.clear({ visibility = { displayed = false }}))
end
Expand Down Expand Up @@ -163,16 +176,16 @@ end

local resource_id = {
["13.31.85"] = { event_name = METHOD.LOCKED, event_handler = event_lock_handler },
["13.48.85"] = { event_name = METHOD.MANUAL, event_handler = event_unlock_indoor_handler },
["13.51.85"] = { event_name = METHOD.MANUAL, event_handler = event_unlock_indoor_handler },
["13.42.85"] = { event_name = METHOD.FINGERPRINT, event_handler = event_unlock_outdoor_handler },
["13.43.85"] = { event_name = METHOD.KEYPAD, event_handler = event_unlock_outdoor_handler },
["13.44.85"] = { event_name = METHOD.RFID, event_handler = event_unlock_outdoor_handler },
["13.151.85"] = { event_name = METHOD.RF447, event_handler = event_unlock_rf447_handler },
["13.45.85"] = { event_name = METHOD.BLUETOOTH, event_handler = event_unlock_remote_handler },
["13.90.85"] = { event_name = METHOD.COMMAND, event_handler = event_unlock_remote_handler },
["13.46.85"] = { event_name = METHOD.KEYPAD, event_handler = event_unlock_otp_handler },
["13.17.85"] = { event_name = METHOD.NO_USE, event_handler = event_door_handler },
["13.48.85"] = { event_name = METHOD.MANUAL, event_handler = event_unlock_handler },
["13.51.85"] = { event_name = METHOD.MANUAL, event_handler = event_unlock_handler },
["13.42.85"] = { event_name = METHOD.FINGERPRINT, event_handler = event_unlock_handler },
["13.43.85"] = { event_name = METHOD.KEYPAD, event_handler = event_unlock_handler },
["13.44.85"] = { event_name = METHOD.RFID, event_handler = event_unlock_handler },
["13.151.85"] = { event_name = METHOD.RF447, event_handler = event_unlock_handler },
["13.45.85"] = { event_name = METHOD.BLUETOOTH, event_handler = event_unlock_handler },
["13.90.85"] = { event_name = METHOD.COMMAND, event_handler = event_unlock_handler },
["13.46.85"] = { event_name = METHOD.KEYPAD, event_handler = event_unlock_handler },
["13.56.85"] = { event_name = METHOD.NO_USE, event_handler = event_battery_handler },
["13.32.85"] = { event_name = METHOD.NO_USE, event_handler = event_abnormal_status_handler },
["13.33.85"] = { event_name = METHOD.NO_USE, event_handler = event_anti_lock_handler },
Expand Down
4 changes: 4 additions & 0 deletions drivers/Aqara/aqara-lock/src/test/test_aqara_lock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ local function test_init()
"highTemperature", "attemptsExceeded" }
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
lockAlarm.supportedAlarmValues(SUPPORTED_ALARM_VALUES, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
Lock.supportedUnlockDirections({"fromInside", "fromOutside"}, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.type("AA")))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.quantity(8)))
test.mock_device.add_test_device(mock_device)
end
test.set_test_init_function(test_init)
Expand Down
9 changes: 7 additions & 2 deletions drivers/Aqara/aqara-presence-sensor/src/discovery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ function discovery.set_device_field(driver, device)

-- persistent fields
if device_cache_value ~= nil then
log.info_with({ hub_logs = true }, string.format("device found in cache. dni= %s", device.device_network_id))
device:set_field(fields.CREDENTIAL, device_cache_value.credential, { persist = true })
device:set_field(fields.DEVICE_IPV4, device_cache_value.ip, { persist = true })
device:set_field(fields.DEVICE_INFO, device_cache_value.device_info, { persist = true })
else
log.error_with({ hub_logs = true }, string.format("device not found in cache. dni= %s", device.device_network_id))
end

driver.datastore.discovery_cache[device.device_network_id] = nil
Expand All @@ -40,21 +43,22 @@ local function try_add_device(driver, device_dni, device_ip)
if driver.datastore.discovery_cache[device_dni] and driver.datastore.discovery_cache[device_dni].credential then
log.info(string.format("use stored credential. This may have expired. dni= %s, ip= %s", device_dni, device_ip))
else
log.error(string.format("Failed to get credential. dni= %s, ip= %s", device_dni, device_ip))
log.error_with({ hub_logs = true }, string.format("Failed to get credential. The device appears to have already generated a credential. In that case, a device reset is needed to generate a new credential. dni= %s, ip= %s", device_dni, device_ip))
return "credential not found"
end
else
log.info(string.format("success to get credential. dni= %s, ip= %s", device_dni, device_ip))
driver.datastore.discovery_cache[device_dni].credential = credential
end

log.info(string.format("try_create_device. dni= %s, ip= %s", device_dni, device_ip))
log.info_with({ hub_logs = true }, string.format("try_create_device. dni= %s, ip= %s", device_dni, device_ip))
processing_devices[device_dni] = true
driver:try_create_device(create_device_msg)
return nil
end

function discovery.device_added(driver, device)
log.info_with({ hub_logs = true }, string.format("device_added. dni= %s", device.device_network_id))
discovery.set_device_field(driver, device)
processing_devices[device.device_network_id] = nil
driver.lifecycle_handlers.init(driver, device)
Expand Down Expand Up @@ -96,6 +100,7 @@ local function discovery_device(driver)
end

function discovery.do_network_discovery(driver, _, should_continue)
log.info_with({ hub_logs = true }, string.format("discovery start for Aqara FP2"))
while should_continue() do
discovery_device(driver)
socket.sleep(1)
Expand Down
15 changes: 4 additions & 11 deletions drivers/Aqara/aqara-presence-sensor/src/fp2/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local log = require "log"
local json = require "st.json"
local RestClient = require "lunchbox.rest"
local utils = require "utils"
local st_utils = require "st.utils"

local fp2_api = {}
fp2_api.__index = fp2_api
Expand Down Expand Up @@ -39,25 +40,17 @@ local function process_rest_response(response, err, partial)
end
end

local function retry_fn(retry_attempts)
local count = 0
return function()
count = count + 1
return count < retry_attempts
end
end

local function do_get(api_instance, path)
return process_rest_response(api_instance.client:get(path, api_instance.headers, retry_fn(5)))
return process_rest_response(RestClient.one_shot_get(api_instance.base_url .. path, api_instance.headers, api_instance.socket_builder))
end

function fp2_api.new_device_manager(device_ip, bridge_info, socket_builder)
local base_url = get_base_url(device_ip)

return setmetatable(
{
headers = ADDITIONAL_HEADERS,
client = RestClient.new(base_url, socket_builder),
headers = st_utils.deep_copy(ADDITIONAL_HEADERS),
socket_builder = socket_builder,
base_url = base_url,
}, fp2_api
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function device_manager.is_valid_connection(driver, device, conn_info)
device.device_network_id))
return false
end

local _, err, status = conn_info:get_attr()
if err or status ~= 200 then
log.warn(string.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ function discovery_helper.get_device_create_msg(driver, device_dni, device_ip)
return nil
end

local device_label = device_info.label or "Aqara-FP2"
if device_dni then
-- To make it easier to distinguish devices, add the last four letters of dni to the label
-- for example, if device_info.label is "Aqara-FP2" and device_dni is "00:11:22:33:44:55", then device_label will be "Aqara-FP2 (4455)"
device_label = string.format("%s (%s)", device_label, string.sub(string.gsub(tostring(device_dni), ":", ""), -4))
end

local create_device_msg = {
type = "LAN",
device_network_id = device_dni,
label = device_info.label,
label = device_label,
profile = "aqara-fp2-zoneDetection",
manufacturer = device_info.manufacturerName,
model = device_info.modelName,
Expand Down
Loading

0 comments on commit 030e6ad

Please sign in to comment.