@@ -39,6 +39,7 @@ local RUN_MODE_SUPPORTED_MODES = "__run_mode_supported_modes"
3939local CURRENT_RUN_MODE = " __current_run_mode"
4040local CLEAN_MODE_SUPPORTED_MODES = " __clean_mode_supported_modes"
4141local OPERATING_STATE_SUPPORTED_COMMANDS = " __operating_state_supported_commands"
42+ local SERVICE_AREA_PROFILED = " __SERVICE_AREA_PROFILED"
4243
4344local subscribed_attributes = {
4445 [capabilities .mode .ID ] = {
@@ -76,12 +77,7 @@ local function component_to_endpoint(device, component_name)
7677 return find_default_endpoint (device , clusters .RvcOperationalState .ID )
7778end
7879
79- local function device_init (driver , device )
80- device :subscribe ()
81- device :set_component_to_endpoint_fn (component_to_endpoint )
82- end
83-
84- local function do_configure (driver , device )
80+ local function match_profile (driver , device )
8581 local clean_mode_eps = device :get_endpoints (clusters .RvcCleanMode .ID ) or {}
8682 local service_area_eps = embedded_cluster_utils .get_endpoints (device , clusters .ServiceArea .ID ) or {}
8783
@@ -95,6 +91,20 @@ local function do_configure(driver, device)
9591
9692 device .log .info_with ({hub_logs = true }, string.format (" Updating device profile to %s." , profile_name ))
9793 device :try_update_metadata ({profile = profile_name })
94+ end
95+
96+ local function device_init (driver , device )
97+ device :subscribe ()
98+ device :set_component_to_endpoint_fn (component_to_endpoint )
99+ if not device :get_field (SERVICE_AREA_PROFILED ) and # device :get_endpoints (clusters .ServiceArea .ID ) > 0 then
100+ match_profile (driver , device )
101+ device :set_field (SERVICE_AREA_PROFILED , true )
102+ end
103+ end
104+
105+ local function do_configure (driver , device )
106+ match_profile (driver , device )
107+ device :set_field (SERVICE_AREA_PROFILED , true )
98108 device :send (clusters .RvcOperationalState .attributes .AcceptedCommandList :read ())
99109end
100110
0 commit comments