-
-
Notifications
You must be signed in to change notification settings - Fork 305
Matter - Add Vacuum Cleaner #2516
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: master
Are you sure you want to change the base?
Changes from 6 commits
df64958
81e9e40
8740793
5ddfe01
8ce8fdd
60f0f30
2883aba
3b51d5a
d0c8523
d12f685
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import get from 'get-value'; | ||
| import { Text } from 'preact-i18n'; | ||
|
|
||
| import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts'; | ||
| import { VACUUM_CLEANER_CLEAN_MODE } from '../../../../../../server/utils/constants'; | ||
|
|
||
| const VacuumCleanerCleanModeDeviceFeature = ({ children, ...props }) => { | ||
| const { deviceFeature } = props; | ||
| const { category, type } = deviceFeature; | ||
|
|
||
| function updateValue(e) { | ||
| props.updateValueWithDebounce(deviceFeature, e.currentTarget.value); | ||
| } | ||
|
|
||
| return ( | ||
| <tr> | ||
| <td> | ||
| <i class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${category}.${type}`, { default: 'settings' })}`} /> | ||
| </td> | ||
| <td>{props.rowName}</td> | ||
|
|
||
| <td class="py-0"> | ||
| <div class="justify-content-end"> | ||
| <div class="form-group mb-0"> | ||
| <select value={props.deviceFeature.last_value} onChange={updateValue} class="form-control form-control-sm"> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.AUTO}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.auto`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.QUICK}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.quick`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.QUIET}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.quiet`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.LOW_NOISE}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.low-noise`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.DEEP_CLEAN}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.deep-clean`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.VACUUM}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.vacuum`} /> | ||
| </option> | ||
| <option value={VACUUM_CLEANER_CLEAN_MODE.MOP}> | ||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.clean-mode.mop`} /> | ||
| </option> | ||
| </select> | ||
| </div> | ||
| </div> | ||
| </td> | ||
| </tr> | ||
| ); | ||
| }; | ||
|
|
||
| export default VacuumCleanerCleanModeDeviceFeature; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Component } from 'preact'; | ||
| import cx from 'classnames'; | ||
| import { Text } from 'preact-i18n'; | ||
| import style from './style.css'; | ||
|
|
||
| class VacuumCleanerDockDeviceFeature extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| loading: false | ||
| }; | ||
| } | ||
|
|
||
| dock = async () => { | ||
| await this.setState({ loading: true }); | ||
| this.props.updateValue(this.props.deviceFeature, 1); | ||
| setTimeout(() => { | ||
| this.setState({ loading: false }); | ||
| }, 350); | ||
| }; | ||
|
Comment on lines
+14
to
+20
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. 🧩 Analysis chain🌐 Web query:
💡 Result: No, in Preact class components, setState does not return a Promise that can be awaited. It returns void. Citations:
Tie loading state to the actual command promise and prevent duplicate dock requests.
Proposed fix class VacuumCleanerDockDeviceFeature extends Component {
@@
dock = async () => {
- await this.setState({ loading: true });
- this.props.updateValue(this.props.deviceFeature, 1);
- setTimeout(() => {
- this.setState({ loading: false });
- }, 350);
+ if (this.state.loading) {
+ return;
+ }
+ this.setState({ loading: true });
+ try {
+ await this.props.updateValue(this.props.deviceFeature, 1);
+ } finally {
+ this.setState({ loading: false });
+ }
};
@@
<button
onClick={this.dock}
type="button"
+ disabled={loading}
class={cx('btn', 'btn-outline-primary', 'btn-sm', style.btnLoading, {
'btn-loading': loading
})}
>Also applies to: 30-35 🤖 Prompt for AI Agents |
||
|
|
||
| render(props, { loading }) { | ||
| return ( | ||
| <tr> | ||
| <td> | ||
| <i class="fe fe-home" /> | ||
| </td> | ||
| <td>{props.rowName}</td> | ||
| <td class="text-right"> | ||
| <button | ||
| onClick={this.dock} | ||
| type="button" | ||
| class={cx('btn', 'btn-outline-primary', 'btn-sm', style.btnLoading, { | ||
| 'btn-loading': loading | ||
| })} | ||
| > | ||
| <i class="fe fe-home" /> <Text id="dashboard.boxes.devicesInRoom.vacuumDock" /> | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default VacuumCleanerDockDeviceFeature; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||
| import get from 'get-value'; | ||||||||||||||
| import { Text } from 'preact-i18n'; | ||||||||||||||
|
|
||||||||||||||
| import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts'; | ||||||||||||||
| import { VACUUM_CLEANER_MODE } from '../../../../../../server/utils/constants'; | ||||||||||||||
|
|
||||||||||||||
| const VacuumCleanerModeDeviceFeature = ({ children, ...props }) => { | ||||||||||||||
| const { deviceFeature } = props; | ||||||||||||||
| const { category, type } = deviceFeature; | ||||||||||||||
|
|
||||||||||||||
| function updateValue(e) { | ||||||||||||||
| props.updateValueWithDebounce(deviceFeature, e.currentTarget.value); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+11
to
+13
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. Cast selected mode to number before updating value.
🔧 Proposed fix function updateValue(e) {
- props.updateValueWithDebounce(deviceFeature, e.currentTarget.value);
+ props.updateValueWithDebounce(deviceFeature, Number(e.currentTarget.value));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <tr> | ||||||||||||||
| <td> | ||||||||||||||
| <i class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${category}.${type}`, { default: 'settings' })}`} /> | ||||||||||||||
| </td> | ||||||||||||||
| <td>{props.rowName}</td> | ||||||||||||||
|
|
||||||||||||||
| <td class="py-0"> | ||||||||||||||
| <div class="justify-content-end"> | ||||||||||||||
| <div class="form-group mb-0"> | ||||||||||||||
| <select value={props.deviceFeature.last_value} onChange={updateValue} class="form-control form-control-sm"> | ||||||||||||||
| <option value={VACUUM_CLEANER_MODE.IDLE}> | ||||||||||||||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.mode.idle`} /> | ||||||||||||||
| </option> | ||||||||||||||
| <option value={VACUUM_CLEANER_MODE.CLEANING}> | ||||||||||||||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.mode.cleaning`} /> | ||||||||||||||
| </option> | ||||||||||||||
| <option value={VACUUM_CLEANER_MODE.MAPPING}> | ||||||||||||||
| <Text id={`deviceFeatureAction.category.vacuum-cleaner.mode.mapping`} /> | ||||||||||||||
| </option> | ||||||||||||||
| </select> | ||||||||||||||
| </div> | ||||||||||||||
| </div> | ||||||||||||||
| </td> | ||||||||||||||
| </tr> | ||||||||||||||
| ); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| export default VacuumCleanerModeDeviceFeature; | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Text } from 'preact-i18n'; | ||
| import cx from 'classnames'; | ||
|
|
||
| const VacuumCleanerStateDeviceValue = props => { | ||
| const { last_value: lastValue = null } = props.deviceFeature; | ||
| const valued = lastValue !== null; | ||
|
|
||
| return ( | ||
| <span | ||
| class={cx('badge', { | ||
| 'bg-primary': valued, | ||
| 'bg-secondary': !valued | ||
| })} | ||
| > | ||
| {!valued && <Text id="dashboard.boxes.devicesInRoom.noValue" />} | ||
| {valued && ( | ||
| <Text id={`deviceFeatureValue.category.vacuum-cleaner.state.${lastValue}`}> | ||
| <Text id={`deviceFeatureValue.category.vacuum-cleaner.state.unknown`} fields={{ value: lastValue }} /> | ||
| </Text> | ||
| )} | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| export default VacuumCleanerStateDeviceValue; |
Uh oh!
There was an error while loading. Please reload this page.