-
Notifications
You must be signed in to change notification settings - Fork 521
Add fanSpeedPercent to Thermostat device types #2549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,16 +17,15 @@ local log = require "log" | |||||||||||||||||||||
| local clusters = require "st.matter.clusters" | ||||||||||||||||||||||
| local embedded_cluster_utils = require "embedded-cluster-utils" | ||||||||||||||||||||||
| local im = require "st.matter.interaction_model" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local MatterDriver = require "st.matter.driver" | ||||||||||||||||||||||
| local utils = require "st.utils" | ||||||||||||||||||||||
| local version = require "version" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local SUPPORTED_COMPONENT_CAPABILITIES = "__supported_component_capabilities" | ||||||||||||||||||||||
| -- declare match_profile function for use throughout file | ||||||||||||||||||||||
| local match_profile | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| -- Include driver-side definitions when lua libs api version is < 10 | ||||||||||||||||||||||
| local version = require "version" | ||||||||||||||||||||||
| if version.api < 10 then | ||||||||||||||||||||||
| clusters.HepaFilterMonitoring = require "HepaFilterMonitoring" | ||||||||||||||||||||||
| clusters.ActivatedCarbonFilterMonitoring = require "ActivatedCarbonFilterMonitoring" | ||||||||||||||||||||||
|
|
@@ -966,6 +965,7 @@ local function match_modular_profile_thermostat(driver, device) | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| if #fan_eps > 0 then | ||||||||||||||||||||||
| table.insert(main_component_capabilities, capabilities.fanMode.ID) | ||||||||||||||||||||||
| table.insert(main_component_capabilities, capabilities.fanSpeedPercent.ID) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| if #rock_eps > 0 then | ||||||||||||||||||||||
| table.insert(main_component_capabilities, capabilities.fanOscillationMode.ID) | ||||||||||||||||||||||
|
|
@@ -1392,7 +1392,11 @@ local function system_mode_handler(driver, device, ib, response) | |||||||||||||||||||||
| return | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local supported_modes = device:get_latest_state(device:endpoint_to_component(ib.endpoint_id), capabilities.thermostatMode.ID, capabilities.thermostatMode.supportedThermostatModes.NAME) or {} | ||||||||||||||||||||||
| local supported_modes = device:get_latest_state( | ||||||||||||||||||||||
| device:endpoint_to_component(ib.endpoint_id), | ||||||||||||||||||||||
| capabilities.thermostatMode.ID, | ||||||||||||||||||||||
| capabilities.thermostatMode.supportedThermostatModes.NAME | ||||||||||||||||||||||
| ) or {} | ||||||||||||||||||||||
| -- check that the given mode was in the supported modes list | ||||||||||||||||||||||
| if tbl_contains(supported_modes, THERMOSTAT_MODE_MAP[ib.data.value].NAME) then | ||||||||||||||||||||||
| device:emit_event_for_endpoint(ib.endpoint_id, THERMOSTAT_MODE_MAP[ib.data.value]()) | ||||||||||||||||||||||
|
|
@@ -1538,39 +1542,59 @@ local function fan_mode_handler(driver, device, ib, response) | |||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local function fan_mode_sequence_handler(driver, device, ib, response) | ||||||||||||||||||||||
| local supportedFanModes, supported_fan_modes_attribute | ||||||||||||||||||||||
| local supported_fan_modes, supported_fan_modes_capability, supported_fan_modes_attribute | ||||||||||||||||||||||
| if ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH then | ||||||||||||||||||||||
| supportedFanModes = { "off", "low", "medium", "high" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "low", "medium", "high" } | ||||||||||||||||||||||
| elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_HIGH then | ||||||||||||||||||||||
| supportedFanModes = { "off", "low", "high" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "low", "high" } | ||||||||||||||||||||||
| elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH_AUTO then | ||||||||||||||||||||||
| supportedFanModes = { "off", "low", "medium", "high", "auto" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "low", "medium", "high", "auto" } | ||||||||||||||||||||||
| elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_LOW_HIGH_AUTO then | ||||||||||||||||||||||
| supportedFanModes = { "off", "low", "high", "auto" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "low", "high", "auto" } | ||||||||||||||||||||||
| elseif ib.data.value == clusters.FanControl.attributes.FanModeSequence.OFF_HIGH_AUTO then | ||||||||||||||||||||||
| supportedFanModes = { "off", "high", "auto" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "high", "auto" } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| supportedFanModes = { "off", "high" } | ||||||||||||||||||||||
| supported_fan_modes = { "off", "high" } | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if device:supports_capability_by_id(capabilities.airPurifierFanMode.ID) then | ||||||||||||||||||||||
| supported_fan_modes_attribute = capabilities.airPurifierFanMode.supportedAirPurifierFanModes | ||||||||||||||||||||||
| supported_fan_modes_capability = capabilities.airPurifierFanMode | ||||||||||||||||||||||
| supported_fan_modes_attribute = supported_fan_modes_capability.supportedAirPurifierFanModes | ||||||||||||||||||||||
| elseif device:supports_capability_by_id(capabilities.airConditionerFanMode.ID) then | ||||||||||||||||||||||
| supported_fan_modes_attribute = capabilities.airConditionerFanMode.supportedAcFanModes | ||||||||||||||||||||||
| supported_fan_modes_capability = capabilities.airConditionerFanMode | ||||||||||||||||||||||
| supported_fan_modes_attribute = supported_fan_modes_capability.supportedAcFanModes | ||||||||||||||||||||||
| elseif device:supports_capability_by_id(capabilities.thermostatFanMode.ID) then | ||||||||||||||||||||||
| supported_fan_modes_capability = capabilities.thermostatFanMode | ||||||||||||||||||||||
| supported_fan_modes_attribute = capabilities.thermostatFanMode.supportedThermostatFanModes | ||||||||||||||||||||||
| -- Our thermostat fan mode control is not granular enough to handle all of the supported modes | ||||||||||||||||||||||
| if ib.data.value >= clusters.FanControl.attributes.FanModeSequence.OFF_LOW_MED_HIGH_AUTO and | ||||||||||||||||||||||
| ib.data.value <= clusters.FanControl.attributes.FanModeSequence.OFF_ON_AUTO then | ||||||||||||||||||||||
| supportedFanModes = { "auto", "on" } | ||||||||||||||||||||||
| supported_fan_modes = { "auto", "on" } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| supportedFanModes = { "on" } | ||||||||||||||||||||||
| supported_fan_modes = { "on" } | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| supported_fan_modes_attribute = capabilities.fanMode.supportedFanModes | ||||||||||||||||||||||
| supported_fan_modes_capability = capabilities.fanMode | ||||||||||||||||||||||
| supported_fan_modes_attribute = supported_fan_modes_capability.supportedFanModes | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| -- remove 'off' as a supported fan mode for thermostat device types, unless the | ||||||||||||||||||||||
| -- device previously had 'off' as a supported fan mode to avoid breaking routines | ||||||||||||||||||||||
| if get_device_type(device) == THERMOSTAT_DEVICE_TYPE_ID then | ||||||||||||||||||||||
| local prev_supported_fan_modes = device:get_latest_state( | ||||||||||||||||||||||
| device:endpoint_to_component(ib.endpoint_id), | ||||||||||||||||||||||
| supported_fan_modes_capability.ID, | ||||||||||||||||||||||
| supported_fan_modes_attribute.NAME | ||||||||||||||||||||||
| ) or {} | ||||||||||||||||||||||
| if not tbl_contains(prev_supported_fan_modes, "off") then | ||||||||||||||||||||||
| local _, off_idx = tbl_contains(supported_fan_modes, "off") | ||||||||||||||||||||||
| if off_idx then | ||||||||||||||||||||||
| table.remove(supported_fan_modes, off_idx) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
Comment on lines
+1589
to
+1594
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to wonder, we don't expect this value to change, do we? I almost wonder if it makes sense to just return early if some However, if we don't go that route, then:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this rule wouldn't work for |
||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local event = supported_fan_modes_attribute(supportedFanModes, {visibility = {displayed = false}}) | ||||||||||||||||||||||
| local event = supported_fan_modes_attribute(supported_fan_modes, {visibility = {displayed = false}}) | ||||||||||||||||||||||
| device:emit_event_for_endpoint(ib.endpoint_id, event) | ||||||||||||||||||||||
|
Comment on lines
+1597
to
1598
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit |
||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you checked if any routines use
off? want to make sure this isn't superfluous at this point.