diff --git a/drivers/SmartThings/jbl/src/discovery.lua b/drivers/SmartThings/jbl/src/discovery.lua index 92150d6efa..b698ca66b1 100644 --- a/drivers/SmartThings/jbl/src/discovery.lua +++ b/drivers/SmartThings/jbl/src/discovery.lua @@ -9,23 +9,24 @@ local st_utils = require "st.utils" local discovery = {} -- mapping from device DNI to info needed at discovery/init time -local device_discovery_cache = {} +local joined_device = {} -local function set_device_field(driver, device) +function discovery.set_device_field(driver, device) log.info(string.format("set_device_field : %s", device.device_network_id)) - local device_cache_value = device_discovery_cache[device.device_network_id] + local device_cache_value = driver.datastore.discovery_cache[device.device_network_id] -- persistent fields 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}) device:set_field(fields.CREDENTIAL, device_cache_value.credential , {persist = true}) + device:set_field(fields.DEVICE_INFO, device_cache_value.device_info , {persist = true}) + driver.datastore.discovery_cache[device.device_network_id] = nil end local function update_device_discovery_cache(driver, dni, ip, credential) log.info(string.format("update_device_discovery_cache for device dni: %s, %s", dni, ip)) local device_info = driver.discovery_helper.get_device_info(driver, dni, ip) - device_discovery_cache[dni] = { + driver.datastore.discovery_cache[dni] = { ip = ip, device_info = device_info, credential = credential, @@ -39,6 +40,7 @@ local function try_add_device(driver, device_dni, device_ip) if not credential then log.error(string.format("failed to get credential. dni=%s, ip=%s", device_dni, device_ip)) + joined_device[device_dni] = nil return end @@ -49,8 +51,9 @@ end function discovery.device_added(driver, device) log.info("device_added : dni = " .. tostring(device.device_network_id)) - set_device_field(driver, device) - device_discovery_cache[device.device_network_id] = nil + + discovery.set_device_field(driver, device) + joined_device[device.device_network_id] = nil driver.lifecycle_handlers.init(driver, device) end @@ -75,8 +78,9 @@ local function discovery_device(driver) log.info(string.format("discovery_device dni, ip = %s, %s", dni, ip)) if not known_devices or not known_devices[dni] then log.trace(string.format("unknown dni= %s, ip= %s", dni, ip)) - if not device_discovery_cache[dni] then + if not joined_device[dni] then try_add_device(driver, dni, ip) + joined_device[dni] = true end else log.trace(string.format("known dni= %s, ip= %s", dni, ip)) diff --git a/drivers/SmartThings/jbl/src/init.lua b/drivers/SmartThings/jbl/src/init.lua index a80874086e..d707c27376 100644 --- a/drivers/SmartThings/jbl/src/init.lua +++ b/drivers/SmartThings/jbl/src/init.lua @@ -160,6 +160,11 @@ local function device_init(driver, device) driver.controlled_devices[device_dni] = device + if driver.datastore.discovery_cache[device_dni] then + log.warn("set unsaved device field") + discovery.set_device_field(driver, device) + end + local device_ip = device:get_field(fields.DEVICE_IPV4) local device_info = device:get_field(fields.DEVICE_INFO) local credential = device:get_field(fields.CREDENTIAL) @@ -214,6 +219,10 @@ local lan_driver = Driver("jbl", } ) +if lan_driver.datastore.discovery_cache == nil then + lan_driver.datastore.discovery_cache = {} +end + lan_driver:call_on_schedule(CONNECTION_MONITORING_INTERVAL, connection_monitoring, "JBL Connection monitoring thread") log.info("Starting lan driver") diff --git a/drivers/SmartThings/jbl/src/jbl/api.lua b/drivers/SmartThings/jbl/src/jbl/api.lua index 2c24869e89..3cebabce55 100644 --- a/drivers/SmartThings/jbl/src/jbl/api.lua +++ b/drivers/SmartThings/jbl/src/jbl/api.lua @@ -104,7 +104,22 @@ function jbl_api.get_credential(bridge_ip, socket_builder) end function jbl_api.get_info(device_ip, socket_builder) - return process_rest_response(RestClient.one_shot_get(get_base_url(device_ip) .. "/info", ADDITIONAL_HEADERS, socket_builder)) + local raw_device_info = process_rest_response(RestClient.one_shot_get(get_base_url(device_ip) .. "/info", ADDITIONAL_HEADERS, socket_builder)) + if raw_device_info == nil then + log.error("failed to get device info") + return nil + end + + local device_info = { + deviceType = raw_device_info.deviceType or "", + firmwareVersion = raw_device_info.firmwareVersion or "", + label = raw_device_info.label or "", + manufacturerName = raw_device_info.manufacturerName or "", + modelName = raw_device_info.modelName or "", + serialNumber = raw_device_info.serialNumber or "", + } + + return device_info end function jbl_api:get_status() diff --git a/drivers/SmartThings/matter-button/profiles/button-battery.yml b/drivers/SmartThings/matter-button/profiles/button-battery.yml index 6b43669059..b614393f1e 100644 --- a/drivers/SmartThings/matter-button/profiles/button-battery.yml +++ b/drivers/SmartThings/matter-button/profiles/button-battery.yml @@ -11,4 +11,4 @@ components: - id: refresh version: 1 categories: - - name: RemoteController + - name: Button diff --git a/drivers/SmartThings/matter-button/profiles/button.yml b/drivers/SmartThings/matter-button/profiles/button.yml index 6fca9b10a8..6c6bced1c2 100644 --- a/drivers/SmartThings/matter-button/profiles/button.yml +++ b/drivers/SmartThings/matter-button/profiles/button.yml @@ -9,4 +9,4 @@ components: - id: refresh version: 1 categories: - - name: RemoteController + - name: Button diff --git a/drivers/SmartThings/matter-switch/fingerprints.yml b/drivers/SmartThings/matter-switch/fingerprints.yml index 1887bf275c..8865322f43 100644 --- a/drivers/SmartThings/matter-switch/fingerprints.yml +++ b/drivers/SmartThings/matter-switch/fingerprints.yml @@ -1926,7 +1926,12 @@ matterManufacturer: vendorId: 0x100b productId: 0x228F deviceProfileName: light-color-level-2200K-6500K - +#Zemismart + - id: "5020/61154" + deviceLabel: Zemismart Inline Module + vendorId: 0x139C + productId: 0xEEE2 + deviceProfileName: switch-binary #Bridge devices need manufacturer specific fingerprints until #bridge support is released to all hubs. This is because of the way generic diff --git a/drivers/SmartThings/matter-switch/src/init.lua b/drivers/SmartThings/matter-switch/src/init.lua index 098aa8345f..95da84f29a 100644 --- a/drivers/SmartThings/matter-switch/src/init.lua +++ b/drivers/SmartThings/matter-switch/src/init.lua @@ -85,14 +85,14 @@ local function initialize_switch(driver, device) end device:set_field(SWITCH_INITIALIZED, true) - -- The case where num_server_eps == 1 is a workaround for devices that have the On/Off + -- The case where num_server_eps > 0 is a workaround for devices that have the On/Off -- Light Switch device type but implement the On Off cluster as server (which is against the spec -- for this device type). By default, we do not support On/Off Light Switch because by spec these -- devices need bindings to work correctly (On/Off cluster is client in this case), so this device type -- does not have a generic fingerprint and will join as a matter-thing. However, we have -- seen some devices claim to be On/Off Light Switch device type and still implement On/Off server, so this -- is a workaround for those devices. - if num_server_eps == 1 and detect_matter_thing(device) == true then + if num_server_eps > 0 and detect_matter_thing(device) == true then device:try_update_metadata({profile = "switch-binary"}) end end diff --git a/drivers/SmartThings/zigbee-motion-sensor/src/test/test_smartsense_motion_sensor.lua b/drivers/SmartThings/zigbee-motion-sensor/src/test/test_smartsense_motion_sensor.lua index 3f74d72da1..64a5b01dfe 100644 --- a/drivers/SmartThings/zigbee-motion-sensor/src/test/test_smartsense_motion_sensor.lua +++ b/drivers/SmartThings/zigbee-motion-sensor/src/test/test_smartsense_motion_sensor.lua @@ -71,7 +71,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "|") + build_motion_status_message(mock_device, "\x7C") }) 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.motionSensor.motion.inactive())) @@ -85,7 +85,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "~") + build_motion_status_message(mock_device, "\x7E") }) 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.motionSensor.motion.active())) @@ -99,7 +99,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "X") + build_motion_status_message(mock_device, "\x58") }) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(70))) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.motionSensor.motion.inactive())) @@ -113,7 +113,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "Z") + build_motion_status_message(mock_device, "\x5A") }) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(70))) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.motionSensor.motion.active())) @@ -127,7 +127,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "½") + build_motion_status_message(mock_device, "\xBD") }) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.motionSensor.motion.inactive())) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.signalStrength.lqi(50))) @@ -140,7 +140,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "¿") + build_motion_status_message(mock_device, "\xBF") }) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.motionSensor.motion.active())) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.signalStrength.lqi(50))) @@ -153,7 +153,7 @@ test.register_coroutine_test( function() test.socket.zigbee:__queue_receive({ mock_device.id, - build_motion_status_message(mock_device, "0") + build_motion_status_message(mock_device, "\x30") }) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(0))) test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.motionSensor.motion.inactive())) @@ -172,4 +172,4 @@ test.register_coroutine_test( end ) -test.run_registered_tests() \ No newline at end of file +test.run_registered_tests()