Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion drivers/SmartThings/zigbee-contact/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ local function do_configure(self, device)
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 0x01))
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local function added_handler(driver, device)
device:emit_event(capabilities.batteryLevel.type("CR1632"))
device:emit_event(capabilities.batteryLevel.quantity(1))
device:emit_event(capabilities.batteryLevel.battery("normal"))
device:emit_event(capabilities.contactSensor.contact.closed())
emit_event_if_latest_state_missing(device, "main", capabilities.contactSensor, capabilities.contactSensor.contact.NAME, capabilities.contactSensor.contact.open())
end

local function contact_status_handler(self, device, value, zb_rx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,21 @@ test.register_coroutine_test(
test.register_coroutine_test(
"added lifecycle handler",
function()
-- The initial contactSensor event should be send during the device's first time onboarding
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.batteryLevel.type("CR1632")))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.batteryLevel.quantity(1)))
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
capabilities.batteryLevel.battery("normal")))
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
capabilities.contactSensor.contact.closed()))
capabilities.contactSensor.contact.open()))
test.wait_for_events()
-- Avoid sending the initial contactSensor event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle.
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.batteryLevel.type("CR1632")))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.batteryLevel.quantity(1)))
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
capabilities.batteryLevel.battery("normal")))
end
)

Expand Down
8 changes: 7 additions & 1 deletion drivers/SmartThings/zigbee-lock/src/samsungsds/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ local refresh = function(driver, device, cmd)
-- do nothing in refresh capability handler
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local device_added = function(self, device)
lock_utils.populate_state_from_data(device)
device:emit_event(capabilities.lock.lock.unlocked())
emit_event_if_latest_state_missing(device, "main", capabilities.lock, capabilities.lock.lock.NAME, capabilities.lock.lock.unlocked())
device:emit_event(capabilities.battery.battery(100))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1377,11 +1377,17 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Device added function handler",
function()
-- The initial lock event should be send during the device's first time onboarding
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added"})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(100)))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.lock.lock.unlocked()))
test.wait_for_events()
-- Avoid sending the initial lock event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle.
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added"})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(100)))
test.wait_for_events()
end
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ local function beep_handler(self, device, command)
end
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local function added_handler(self, device)
device:emit_event(PresenceSensor.presence("present"))
emit_event_if_latest_state_missing(device, "main", PresenceSensor, PresenceSensor.presence.NAME, PresenceSensor.presence("present"))
end

local function init_handler(self, device, event, args)
Expand Down
8 changes: 7 additions & 1 deletion drivers/SmartThings/zigbee-presence-sensor/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ local function beep_handler(self, device, command)
device:send(IdentifyCluster.server.commands.Identify(device, BEEP_IDENTIFY_TIME))
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local function added_handler(self, device)
device:emit_event(PresenceSensor.presence("present"))
emit_event_if_latest_state_missing(device, "main", PresenceSensor, PresenceSensor.presence.NAME, PresenceSensor.presence("present"))
device:set_field(IS_PRESENCE_BASED_ON_BATTERY_REPORTS, false, {persist = true})
device:send(PowerConfiguration.attributes.BatteryVoltage:read(device))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,20 @@ end
zigbee_test_utils.prepare_zigbee_env_info()

local add_device = function()
-- The initial presenceSensor event should be send during the device's first time onboarding
test.socket.device_lifecycle:__queue_receive({ mock_simple_device.id, "added"})
test.socket.capability:__expect_send(mock_simple_device:generate_test_message("main",
capabilities.presenceSensor.presence("present")
))
test.wait_for_events()
end

local add_device_after_switch_over = function()
-- Avoid sending the initial presenceSensor event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle.
test.socket.device_lifecycle:__queue_receive({ mock_simple_device.id, "added"})
test.wait_for_events()
end

local function test_init()
test.mock_device.add_test_device(mock_simple_device)end

Expand Down Expand Up @@ -126,6 +133,7 @@ test.register_coroutine_test(
"Added lifecycle should be handlded",
function ()
add_device()
add_device_after_switch_over()
end
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ test.register_message_test(
)

local add_device = function()
-- The initial presenceSensor event should be send during the device's first time onboarding
test.socket.device_lifecycle:__queue_receive({ mock_simple_device.id, "added"})
test.socket.capability:__expect_send(mock_simple_device:generate_test_message("main",
capabilities.presenceSensor.presence("present")
Expand All @@ -120,6 +121,16 @@ local add_device = function()
test.wait_for_events()
end

local add_device_after_switch_over = function()
-- Avoid sending the initial presenceSensor event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle.
test.socket.device_lifecycle:__queue_receive({ mock_simple_device.id, "added"})
test.socket.zigbee:__expect_send({
mock_simple_device.id,
PowerConfiguration.attributes.BatteryVoltage:read(mock_simple_device)
})
test.wait_for_events()
end

test.register_coroutine_test(
"Battery Voltage test cases when polling from hub",
function()
Expand Down Expand Up @@ -185,6 +196,7 @@ test.register_coroutine_test(
"Added lifecycle should be handlded",
function ()
add_device()
add_device_after_switch_over()
end
)

Expand Down
10 changes: 8 additions & 2 deletions drivers/SmartThings/zigbee-thermostat/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,23 @@ local function device_init(driver, device)
do_refresh(driver, device)
end

local function emit_component_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component.id, capability.ID, attribute_name) == nil then
device:emit_component_event(component, value)
end
end

local function device_added(driver, device)
supported_thermostat_modes_handler(driver, device, nil)
device:emit_event(capabilities.thermostatHeatingSetpoint.heatingSetpoint({value = 21.0, unit = "C"}))
device:emit_event(capabilities.temperatureMeasurement.temperature({value = 27.0, unit = "C"}))
device:emit_event(capabilities.thermostatMode.thermostatMode.manual())
device:emit_event(capabilities.valve.valve.open())
device:emit_component_event(device.profile.components.ChildLock, capabilities.lock.lock.unlocked())
device:emit_event(capabilities.hardwareFault.hardwareFault.clear())
device:emit_event(valveCalibration.calibrationState.calibrationPending())
device:emit_event(invisibleCapabilities.invisibleCapabilities({""}))
device:emit_event(capabilities.battery.battery(100))
emit_component_event_if_latest_state_missing(device, device.profile.components.main, capabilities.valve, capabilities.valve.valve.NAME, capabilities.valve.valve.open())
emit_component_event_if_latest_state_missing(device, device.profile.components.ChildLock, capabilities.lock, capabilities.lock.lock.NAME, capabilities.lock.lock.unlocked())
end

local function thermostat_alarm_status_handler(driver, device, value, zb_rx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,46 +73,8 @@ end

test.set_test_init_function(test_init)

-- test.register_coroutine_test(
-- "Handle added lifecycle",
-- function()
-- test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main",
-- capabilities.thermostatMode.supportedThermostatModes({
-- capabilities.thermostatMode.thermostatMode.manual.NAME,
-- capabilities.thermostatMode.thermostatMode.antifreezing.NAME
-- }, { visibility = { displayed = false } }))
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpoint({value = 21.0, unit = "C"}))
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({value = 27.0, unit = "C"}))
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.thermostatMode.thermostatMode.manual())
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.valve.valve.open())
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("ChildLock", capabilities.lock.lock.unlocked())
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.hardwareFault.hardwareFault.clear())
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", valveCalibration.calibrationState.calibrationPending())
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", invisibleCapabilities.invisibleCapabilities({""}))
-- )
-- test.socket.capability:__expect_send(
-- mock_device:generate_test_message("main", capabilities.battery.battery(100))
-- )
-- end
-- )




test.register_coroutine_test(
Expand Down Expand Up @@ -312,4 +274,76 @@ test.register_coroutine_test(
end
)
--]]
test.register_coroutine_test(
"Handle added lifecycle",
function()
-- The initial valve and lock event should be send during the device's first time onboarding
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(
mock_device:generate_test_message("main",
capabilities.thermostatMode.supportedThermostatModes({
capabilities.thermostatMode.thermostatMode.manual.NAME,
capabilities.thermostatMode.thermostatMode.antifreezing.NAME
}, { visibility = { displayed = false } }))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpoint({value = 21.0, unit = "C"}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({value = 27.0, unit = "C"}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatMode.thermostatMode.manual())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.hardwareFault.hardwareFault.clear())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", valveCalibration.calibrationState.calibrationPending())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", invisibleCapabilities.invisibleCapabilities({""}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.battery.battery(100))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.valve.valve.open())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("ChildLock", capabilities.lock.lock.unlocked())
)
-- Avoid sending the initial open and lock event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle.
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(
mock_device:generate_test_message("main",
capabilities.thermostatMode.supportedThermostatModes({
capabilities.thermostatMode.thermostatMode.manual.NAME,
capabilities.thermostatMode.thermostatMode.antifreezing.NAME
}, { visibility = { displayed = false } }))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatHeatingSetpoint.heatingSetpoint({value = 21.0, unit = "C"}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({value = 27.0, unit = "C"}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.thermostatMode.thermostatMode.manual())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.hardwareFault.hardwareFault.clear())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", valveCalibration.calibrationState.calibrationPending())
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", invisibleCapabilities.invisibleCapabilities({""}))
)
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.battery.battery(100))
)
end
)

test.run_registered_tests()
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ local function do_configure(driver, device)
device:send(Association:Remove({grouping_identifier = 1, node_ids = driver.environment_info.hub_zwave_id}))
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local function device_added(driver, device)
do_refresh(driver, device)
device:emit_event(capabilities.tamperAlert.tamper.clear())
device:emit_event(capabilities.contactSensor.contact.open())
emit_event_if_latest_state_missing(device, "main", capabilities.contactSensor, capabilities.contactSensor.contact.NAME, capabilities.contactSensor.contact.open())
emit_event_if_latest_state_missing(device, "main", capabilities.tamperAlert, capabilities.tamperAlert.tamper.NAME, capabilities.tamperAlert.tamper.clear())
end


local fibaro_door_window_sensor_1 = {
NAME = "fibaro door window sensor 1",
lifecycle_handlers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ local function can_handle_fibaro_door_window_sensor_2(opts, driver, device, cmd,
return false
end

local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

local function device_added(self, device)
device:emit_event(capabilities.tamperAlert.tamper.clear())
device:emit_event(capabilities.contactSensor.contact.open())
device:emit_event(capabilities.temperatureAlarm.temperatureAlarm.cleared())
emit_event_if_latest_state_missing(device, "main", capabilities.tamperAlert, capabilities.tamperAlert.tamper.NAME, capabilities.tamperAlert.tamper.clear())
emit_event_if_latest_state_missing(device, "main", capabilities.contactSensor, capabilities.contactSensor.contact.NAME, capabilities.contactSensor.contact.open())
emit_event_if_latest_state_missing(device, "main", capabilities.temperatureAlarm, capabilities.temperatureAlarm.temperatureAlarm.NAME, capabilities.temperatureAlarm.temperatureAlarm.cleared())
end

local function alarm_report_handler(self, device, cmd)
Expand Down
Loading
Loading