|
1 | | -const StartStopSwitch = require('./startstopswitch.js'); |
| 1 | +const DefaultDevice = require('./default.js'); |
2 | 2 |
|
3 | | -class Vacuum extends StartStopSwitch { |
| 3 | +class Vacuum extends DefaultDevice { |
4 | 4 | static get type() { |
5 | 5 | return 'action.devices.types.VACUUM'; |
6 | 6 | } |
| 7 | + |
| 8 | + static getTraits(item) { |
| 9 | + const members = this.getMembers(item); |
| 10 | + const traits = ['action.devices.traits.StartStop']; |
| 11 | + if ('vacuumDock' in members) traits.push('action.devices.traits.Dock'); |
| 12 | + if ('vacuumLocate' in members) traits.push('action.devices.traits.Locator'); |
| 13 | + if ('vacuumCurrentCycle' in members) traits.push('action.devices.traits.RunCycle'); |
| 14 | + if ('vacuumBattery' in members) traits.push('action.devices.traits.EnergyStorage'); |
| 15 | + return traits; |
| 16 | + } |
| 17 | + |
| 18 | + static get requiredItemTypes() { |
| 19 | + return ['Group']; |
| 20 | + } |
| 21 | + |
| 22 | + static matchesDeviceType(item) { |
| 23 | + return super.matchesDeviceType(item) && Object.keys(this.getMembers(item)).length > 0; |
| 24 | + } |
| 25 | + |
| 26 | + static get supportedMembers() { |
| 27 | + return [ |
| 28 | + { name: 'vacuumPower', types: ['Switch'] }, |
| 29 | + { name: 'vacuumDock', types: ['Switch'] }, |
| 30 | + { name: 'vacuumBattery', types: ['Number', 'Dimmer'] }, |
| 31 | + { name: 'vacuumLocate', types: ['Switch'] }, |
| 32 | + { name: 'vacuumCurrentCycle', types: ['String'] } |
| 33 | + ]; |
| 34 | + } |
| 35 | + |
| 36 | + static getAttributes(item) { |
| 37 | + const attributes = { |
| 38 | + pausable: false |
| 39 | + }; |
| 40 | + |
| 41 | + const members = this.getMembers(item); |
| 42 | + if ('vacuumBattery' in members) { |
| 43 | + attributes.queryOnlyEnergyStorage = true; |
| 44 | + } |
| 45 | + |
| 46 | + return attributes; |
| 47 | + } |
| 48 | + |
| 49 | + static getState(item) { |
| 50 | + const state = { |
| 51 | + isRunning: false, |
| 52 | + isPaused: false |
| 53 | + }; |
| 54 | + const config = this.getConfig(item); |
| 55 | + const members = this.getMembers(item); |
| 56 | + |
| 57 | + for (const member in members) { |
| 58 | + switch (member) { |
| 59 | + case 'vacuumPower': { |
| 60 | + let isRunning = members[member].state === 'ON'; |
| 61 | + if (config.inverted === true) { |
| 62 | + isRunning = !isRunning; |
| 63 | + } |
| 64 | + state.isRunning = isRunning; |
| 65 | + state.isPaused = false; // Default to not paused when running/stopped |
| 66 | + break; |
| 67 | + } |
| 68 | + |
| 69 | + case 'vacuumDock': |
| 70 | + state.isDocked = members[member].state === 'ON'; |
| 71 | + break; |
| 72 | + |
| 73 | + case 'vacuumBattery': { |
| 74 | + const batteryLevel = parseInt(members[member].state) || 0; |
| 75 | + state.descriptiveCapacityRemaining = 'FULL'; |
| 76 | + state.capacityRemaining = [{ unit: 'PERCENTAGE', rawValue: batteryLevel }]; |
| 77 | + if (batteryLevel <= 15) { |
| 78 | + state.descriptiveCapacityRemaining = 'CRITICALLY_LOW'; |
| 79 | + } else if (batteryLevel <= 25) { |
| 80 | + state.descriptiveCapacityRemaining = 'LOW'; |
| 81 | + } else if (batteryLevel <= 75) { |
| 82 | + state.descriptiveCapacityRemaining = 'MEDIUM'; |
| 83 | + } |
| 84 | + break; |
| 85 | + } |
| 86 | + |
| 87 | + case 'vacuumCurrentCycle': |
| 88 | + state.currentRunCycle = [ |
| 89 | + { |
| 90 | + currentCycle: members[member].state || 'unknown', |
| 91 | + lang: 'en' |
| 92 | + } |
| 93 | + ]; |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
| 97 | + return state; |
| 98 | + } |
7 | 99 | } |
8 | 100 |
|
9 | 101 | module.exports = Vacuum; |
0 commit comments