-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new `setpoints` config that will allow manually setting single/dual setpoints, as well as hiding 1 or more setpoints. Remove the `hide.setpoint` config Fixes #216 BREAKING CHANGE: hide.setpoint is removed
- Loading branch information
1 parent
6747a71
commit d221728
Showing
7 changed files
with
178 additions
and
71 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
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,30 @@ | ||
import { Setpoints } from '../types' | ||
import getEntityType from '../getEntityType' | ||
const DUAL = 'dual' as const | ||
|
||
export default function parseSetpoints( | ||
setpoints: Setpoints | false, | ||
attributes: any | ||
) { | ||
if (setpoints) { | ||
const def = Object.keys(setpoints) | ||
return def.reduce((result, name: string) => { | ||
const sp = setpoints[name] | ||
if (sp?.hide) return result | ||
return { | ||
...result, | ||
[name]: attributes?.[name], | ||
} | ||
}, {}) | ||
} | ||
const entityType = getEntityType(attributes) | ||
if (entityType === DUAL) { | ||
return { | ||
target_temp_low: attributes.target_temp_low, | ||
target_temp_high: attributes.target_temp_high, | ||
} | ||
} | ||
return { | ||
temperature: attributes.temperature, | ||
} | ||
} |
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
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,43 @@ | ||
import parseSetpoints from '../config/setpoints' | ||
|
||
test('single setpoint', () => { | ||
const match = { temperature: 20 } | ||
|
||
expect( | ||
parseSetpoints( | ||
{ temperature: null }, | ||
{ temperature: 20, target_temp_low: 19 } | ||
) | ||
).toEqual(match) | ||
|
||
expect( | ||
parseSetpoints(false, { temperature: 20, target_temp_low: 19 }) | ||
).toEqual(match) | ||
}) | ||
|
||
test('dual setpoint', () => { | ||
const result = parseSetpoints( | ||
{ target_temp_low: null, target_temp_high: null }, | ||
{ target_temp_high: 20, target_temp_low: 19 } | ||
) | ||
|
||
expect(result).toEqual({ target_temp_high: 20, target_temp_low: 19 }) | ||
}) | ||
|
||
test('dual setpoint defaults', () => { | ||
const result = parseSetpoints(false, { | ||
target_temp_high: 20, | ||
target_temp_low: 19, | ||
}) | ||
|
||
expect(result).toEqual({ target_temp_high: 20, target_temp_low: 19 }) | ||
}) | ||
|
||
test('dual setpoint hide one', () => { | ||
const result = parseSetpoints( | ||
{ target_temp_low: { hide: true }, target_temp_high: null }, | ||
{ target_temp_high: 20, target_temp_low: 19 } | ||
) | ||
|
||
expect(result).toEqual({ target_temp_high: 20 }) | ||
}) |
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