forked from tuya/tuya-homebridge
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix switch accessory & add support for Smart IR (wnykq) (#115)
* Fix switch accessory & add support for Smart IR (wnykq) * Run eslint --fix and fix bug with error in JSON.parse * Add new temp sensor for IR devices and revert code for subdevices properties support
- Loading branch information
Showing
8 changed files
with
84 additions
and
49 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
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,23 @@ | ||
import { PlatformAccessory } from 'homebridge'; | ||
import { TuyaPlatform } from '../platform'; | ||
import BaseAccessory from './BaseAccessory'; | ||
import { configureHumiditySensor } from './TemperatureHumiditySensorAccessory/configureHumiditySensor'; | ||
import { configureTemperatureSensor } from './TemperatureHumiditySensorAccessory/configureTemperatureSensor'; | ||
|
||
|
||
export default class TemperatureHumidityIRSensorAccessory extends BaseAccessory { | ||
|
||
constructor(platform: TuyaPlatform, accessory: PlatformAccessory) { | ||
super(platform, accessory); | ||
|
||
configureTemperatureSensor(this); | ||
configureHumiditySensor(this); | ||
} | ||
|
||
requiredSchema() { | ||
return []; | ||
} | ||
|
||
|
||
|
||
} |
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
24 changes: 24 additions & 0 deletions
24
src/accessory/TemperatureHumiditySensorAccessory/configureHumiditySensor.ts
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,24 @@ | ||
import { TuyaDeviceSchemaIntegerProperty } from '../../device/TuyaDevice'; | ||
import { limit } from '../../util/util'; | ||
import BaseAccessory from '../BaseAccessory'; | ||
|
||
export function configureHumiditySensor(accessory: BaseAccessory) { | ||
const schema = accessory.getSchema('va_humidity', 'humidity_value'); | ||
if (!schema) { | ||
accessory.log.warn('HumiditySensor not supported.'); | ||
return; | ||
} | ||
|
||
const service = accessory.accessory.getService(accessory.Service.HumiditySensor) | ||
|| accessory.accessory.addService(accessory.Service.HumiditySensor); | ||
|
||
const property = schema.property as TuyaDeviceSchemaIntegerProperty; | ||
const multiple = Math.pow(10, property ? property.scale : 0); | ||
service.getCharacteristic(accessory.Characteristic.CurrentRelativeHumidity) | ||
.onGet(() => { | ||
const status = accessory.getStatus(schema.code)!; | ||
// this.log.debug('CurrentRelativeHumidity:', 'property =', property, 'multiple =', multiple, 'status =', status); | ||
return limit(status.value as number / multiple, 0, 100); | ||
}); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/accessory/TemperatureHumiditySensorAccessory/configureTemperatureSensor.ts
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,24 @@ | ||
import { TuyaDeviceSchemaIntegerProperty } from '../../device/TuyaDevice'; | ||
import { limit } from '../../util/util'; | ||
import BaseAccessory from '../BaseAccessory'; | ||
|
||
export function configureTemperatureSensor(accessory: BaseAccessory) { | ||
const schema = accessory.getSchema('va_temperature'); | ||
if (!schema) { | ||
accessory.log.warn('TemperatureSensor not supported.'); | ||
return; | ||
} | ||
|
||
const service = accessory.accessory.getService(accessory.Service.TemperatureSensor) | ||
|| accessory.accessory.addService(accessory.Service.TemperatureSensor); | ||
|
||
const property = schema.property as TuyaDeviceSchemaIntegerProperty; | ||
const multiple = Math.pow(10, property ? property.scale : 0); | ||
service.getCharacteristic(accessory.Characteristic.CurrentTemperature) | ||
.onGet(() => { | ||
const status = accessory.getStatus(schema.code)!; | ||
// accessory.log.debug('CurrentTemperature:', 'property =', property, 'multiple =', multiple, 'status =', status); | ||
return limit(status.value as number / multiple, -270, 100); | ||
}); | ||
|
||
} |
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