This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add filter life & condition (thanks @jeffmaki!)
part of #40
- Loading branch information
Showing
3 changed files
with
123 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,60 @@ | ||
import type { Service, Characteristic } from 'homebridge' | ||
import type { GetDeviceResponse } from '../thinq/apiTypes' | ||
|
||
import { HomebridgeLgThinqPlatform } from '../platform' | ||
import AbstractCharacteristic from './abstractCharacteristic' | ||
|
||
type State = 0 | 1 | ||
|
||
type ApiValue = boolean | ||
|
||
export default class FilterChangeCharacteristic extends AbstractCharacteristic< | ||
State, | ||
// @ts-expect-error This characteristic is a hack | ||
ApiValue, | ||
typeof Characteristic.FilterChangeIndication | ||
> { | ||
constructor( | ||
platform: HomebridgeLgThinqPlatform, | ||
service: Service, | ||
deviceId: string, | ||
) { | ||
super( | ||
platform, | ||
service, | ||
deviceId, | ||
platform.Characteristic.FilterChangeIndication, | ||
'Operation', | ||
// @ts-expect-error This characteristic is a hack | ||
'_fake_filter_change_value', | ||
) | ||
} | ||
|
||
// Override default handleUpdatedSnapshot() to ignore based on mode | ||
handleUpdatedSnapshot(snapshot: GetDeviceResponse['result']['snapshot']) { | ||
const maxTime = snapshot['airState.filterMngStates.maxTime'] | ||
const useTime = snapshot['airState.filterMngStates.useTime'] | ||
const shouldFilterBeChanged = useTime >= maxTime | ||
|
||
super.handleUpdatedSnapshot({ | ||
...snapshot, | ||
// @ts-expect-error This characteristic is a hack | ||
_fake_filter_change_value: shouldFilterBeChanged, | ||
}) | ||
} | ||
|
||
getStateFromApiValue(apiValue: ApiValue): State { | ||
return apiValue | ||
? this.characteristic.CHANGE_FILTER | ||
: this.characteristic.FILTER_OK | ||
} | ||
|
||
handleSet = undefined | ||
|
||
getApiValueFromState(state: State): ApiValue { | ||
if (state === this.characteristic.CHANGE_FILTER) { | ||
return true | ||
} | ||
return false | ||
} | ||
} |
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,55 @@ | ||
import type { Service, Characteristic } from 'homebridge' | ||
import type { GetDeviceResponse } from '../thinq/apiTypes' | ||
|
||
import { HomebridgeLgThinqPlatform } from '../platform' | ||
import AbstractCharacteristic from './abstractCharacteristic' | ||
|
||
type State = number | ||
|
||
type ApiValue = number | ||
|
||
export default class FilterLifeCharacteristic extends AbstractCharacteristic< | ||
State, | ||
ApiValue, | ||
typeof Characteristic.FilterLifeLevel | ||
> { | ||
constructor( | ||
platform: HomebridgeLgThinqPlatform, | ||
service: Service, | ||
deviceId: string, | ||
) { | ||
super( | ||
platform, | ||
service, | ||
deviceId, | ||
platform.Characteristic.FilterLifeLevel, | ||
'Operation', | ||
// @ts-expect-error This characteristic is a hack | ||
'_fake_filter_life', | ||
) | ||
} | ||
|
||
// Override default handleUpdatedSnapshot() to ignore based on mode | ||
handleUpdatedSnapshot(snapshot: GetDeviceResponse['result']['snapshot']) { | ||
const maxTime = snapshot['airState.filterMngStates.maxTime'] | ||
const useTime = snapshot['airState.filterMngStates.useTime'] | ||
const percentUsed = (useTime / maxTime) * 100 | ||
const filterLife = Math.floor(100 - percentUsed) | ||
|
||
super.handleUpdatedSnapshot({ | ||
...snapshot, | ||
// @ts-expect-error This characteristic is a hack | ||
_fake_filter_life: filterLife, | ||
}) | ||
} | ||
|
||
getStateFromApiValue(apiValue: ApiValue): State { | ||
return apiValue | ||
} | ||
|
||
handleSet = undefined | ||
|
||
getApiValueFromState(state: State): ApiValue { | ||
return state | ||
} | ||
} |
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