-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d43a205
commit 141c12b
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
import Entity from '../Entity'; | ||
import filterObject from '../filterObject'; | ||
|
||
export default class ClimateEntity extends Entity { | ||
constructor(controller, data) { | ||
super(controller, data); | ||
} | ||
|
||
async set({mode, target_temperature_high, target_temperature_low, target_temperature} = {}) { | ||
const query = filterObject({ | ||
mode, | ||
target_temperature_high, | ||
target_temperature_low, | ||
target_temperature | ||
}); | ||
|
||
const args = [this.getPostURL('set')]; | ||
if (Object.values(query).length > 0) { | ||
args.push(query); | ||
} | ||
|
||
return this.controller.post(...args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Entity from '../Entity'; | ||
|
||
export default class LockEntity extends Entity { | ||
constructor(controller, data) { | ||
super(controller, data); | ||
} | ||
|
||
async open() { | ||
return this.controller.post(this.getPostURL('open')); | ||
} | ||
|
||
async lock() { | ||
return this.controller.post(this.getPostURL('lock')); | ||
} | ||
|
||
async unlock() { | ||
return this.controller.post(this.getPostURL('unlock')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {jest, expect, test} from '@jest/globals'; | ||
import {createController, getLastController} from '../../tests/helpers.js'; | ||
import ClimateEntity from '../ClimateEntity'; | ||
|
||
const createData = jest.fn(() => ({ | ||
id: 'climate-name', | ||
state: 'HEATING', | ||
})); | ||
|
||
function createClimateEntity({controller = createController(), data = createData()} = {}) { | ||
return new ClimateEntity(controller, data); | ||
} | ||
|
||
test('it should post to set when set is called', () =>{ | ||
const entity = createClimateEntity(); | ||
const controller = getLastController(); | ||
entity.set({mode: 'HEAT_COOL', target_temperature_high: 72, target_temperature_low: 68}); | ||
expect(controller.post).toHaveBeenLastCalledWith(entity.getPostURL('set'), {mode: 'HEAT_COOL', target_temperature_high: 72, target_temperature_low: 68}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {jest, expect, test} from '@jest/globals'; | ||
import {createController, getLastController} from '../../tests/helpers.js'; | ||
import LockEntity from '../LockEntity'; | ||
|
||
const createData = jest.fn((extra = {}) => Object.assign({ | ||
id: 'lock-name', | ||
state: 'UNLOCKED', | ||
}, extra)); | ||
|
||
|
||
function createLockEntity({controller = createController(), data = createData()} = {}) { | ||
return new LockEntity(controller, data); | ||
} | ||
|
||
test('it should post to open when open is called', () =>{ | ||
const entity = createLockEntity(); | ||
const controller = getLastController(); | ||
entity.open(); | ||
expect(controller.post).toHaveBeenLastCalledWith(entity.getPostURL('open')); | ||
}); | ||
|
||
test('it should post to lock when lock is called', () =>{ | ||
const entity = createLockEntity(); | ||
const controller = getLastController(); | ||
entity.lock(); | ||
expect(controller.post).toHaveBeenLastCalledWith(entity.getPostURL('lock')); | ||
}); | ||
|
||
test('it should post to unlock when unlock is called', () =>{ | ||
const entity = createLockEntity(); | ||
const controller = getLastController(); | ||
entity.unlock(); | ||
expect(controller.post).toHaveBeenLastCalledWith(entity.getPostURL('unlock')); | ||
}); |