Browse Source

Update Accessories

JDierkse 9 tháng trước cách đây
mục cha
commit
e9459044a0

+ 4 - 14
activityAccessory.ts

@@ -23,9 +23,9 @@ export class activityAccessory extends accessory {
 								typeId: device.id,
 								uniqueId: "Activity." + device.id,
 								deviceName: device.name,
-								switchable: device.switchable,
-								dimmable: "true",
-								detailedType: device.type
+								switchable: "false",
+								dimmable: "false",
+								detailedType: ""
 							}
 							activityDevices.push(object)
 						}
@@ -49,22 +49,12 @@ export class activityAccessory extends accessory {
 			.setCharacteristic(this.platform.Characteristic.Model, 'Domotica-Activity')
 			.setCharacteristic(this.platform.Characteristic.SerialNumber, '08000' + accessory.context.device.typeId)
 
-//*
 		this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch)
 
 		this.service.getCharacteristic(this.platform.Characteristic.On)
 			.onGet(this.getOn.bind(this))
 			.onSet(this.setOn.bind(this));
-/*/
-		this.service = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch) || this.accessory.addService(this.platform.Service.StatefulProgrammableSwitch)
 
-		this.service.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent)
-			.onGet(this.getOn.bind(this));
-
-		this.service.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
-			.onGet(this.getOn.bind(this))
-			.onSet(this.setOn.bind(this));
-//*/
 		this.setName(accessory.context.device.deviceName)
 	}
 
@@ -85,7 +75,7 @@ export class activityAccessory extends accessory {
 
 	async setOn(value: CharacteristicValue) {
 		// http://$domoticaIP/external/WebUpdate.php?data=Activity/$id/
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=Activity/' + this.accessory.context.device.typeId + '/')
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=Activity/' + this.accessory.context.device.typeId + '/')
 			.catch((error) => {
 				this.platform.log.debug('activityAccessory::setOn Error ->' + error)
 			})

+ 11 - 9
cameraAccessory.ts

@@ -89,16 +89,18 @@ export class cameraAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.camera) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.motionstate == 'absent') {
-							this.state.Motion = false
-						} else { // present
-							this.state.Motion = true
+				if (devices.hasOwnProperty('camera')) {
+					for (const device of devices.camera) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.motionstate == 'absent') {
+								this.state.Motion = false
+							} else { // present
+								this.state.Motion = true
+							}
+							return this.state.Motion
+							this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
+							break
 						}
-						return this.state.Motion
-						this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
-						break
 					}
 				}
 			})

+ 18 - 45
doorWindowSensorAccessory.ts

@@ -9,7 +9,7 @@ export class doorWindowSensorAccessory extends accessory {
 	private service: Service
 
 	private state = {
-		Position: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
+		ContactSensorState: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED,
 	}
 
 	static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
@@ -61,16 +61,7 @@ export class doorWindowSensorAccessory extends accessory {
 
 		this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
 			.onGet(this.getContactSensorState.bind(this));
-/*
-		this.service.getCharacteristic(this.platform.Characteristic.CurrentPosition)
-			.onGet(this.getCurrentPosition.bind(this));
 
-		this.service.getCharacteristic(this.platform.Characteristic.PositionState)
-			.onGet(this.getPositionState.bind(this));
-
-		this.service.getCharacteristic(this.platform.Characteristic.TargetPosition)
-			.onGet(this.getTargetPosition.bind(this))
-*/
 		this.setName(accessory.context.device.deviceName)
 		this.update()
 	}
@@ -82,14 +73,11 @@ export class doorWindowSensorAccessory extends accessory {
 	setValue(key, value) {
 		if (key == "state" && value != "") {
 			if (value == "Off") {
-				this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
+				this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
 			} else {
-				this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
+				this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
 			}
-/*
-			this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.state.Position)
-			this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.state.Position)
-*/
+			this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState)
 		}
 	}
 
@@ -103,18 +91,19 @@ export class doorWindowSensorAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.doorwindow) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.state == 'closed') {
-							this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
-						} else { // open
-							this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
+				if (devices.hasOwnProperty('doorwindow')) {
+					for (const device of devices.doorwindow) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.state == 'closed') {
+								this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
+							} else { // open
+								this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
+							}
+
+							this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState)
+
+							break
 						}
-/*
-						this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.state.Position)
-						this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.state.Position)
-*/
-						break
 					}
 				}
 			})
@@ -122,24 +111,8 @@ export class doorWindowSensorAccessory extends accessory {
 				this.platform.log.debug('doorWindowSensorAccessory::update Error ->' + error)
 			})
 	}
-/*
-	getCurrentPosition(): CharacteristicValue {
-		return this.state.Position
-	}
 
-	getPositionState(): CharacteristicValue {
-		return this.platform.Characteristic.PositionState.STOPPED;
-	}
-
-	getTargetPosition(): CharacteristicValue {
-		return this.state.Position
-	}
-
-	getPosition(): CharacteristicValue {
-		return this.state.Position
-	}
-*/
 	getContactSensorState(): CharacteristicValue {
-		return this.state.Position
+		return this.state.ContactSensorState
 	}
-}
+}

+ 12 - 8
environmentSensorAccessory.ts

@@ -77,7 +77,7 @@ export class environmentSensorAccessory extends accessory {
 			this.state.Temperature = value / 100
 			this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature)
 		}
-		if (key == "humidity" && value != "") {
+		else if (key == "humidity" && value != "") {
 			this.state.Humidity = value / 100
 			this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
 		}
@@ -93,13 +93,17 @@ export class environmentSensorAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.environment) {
-					if (device.id == this.accessory.context.device.typeId) {
-						this.state.Temperature = device.temperature
-						this.state.Humidity = device.humidity
-						this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature)
-						this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
-						break
+				if (devices.hasOwnProperty('environment')) {
+					for (const device of devices.environment) {
+						if (device.id == this.accessory.context.device.typeId) {
+							this.state.Temperature = device.temperature
+							this.state.Humidity = device.humidity
+
+							this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature)
+							this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
+
+							break
+						}
 					}
 				}
 			})

+ 17 - 15
klikAanKlikUitAccessory.ts

@@ -94,21 +94,23 @@ export class klikAanKlikUitAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.klikaanklikuit) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.state == 'on') {
-							this.state.On = true
-						} else {
-							this.state.On = false
-						}
-						this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
+				if (devices.hasOwnProperty('klikaanklikuit')) {
+					for (const device of devices.klikaanklikuit) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.state == 'on') {
+								this.state.On = true
+							} else {
+								this.state.On = false
+							}
+							this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
 
-						if (device.dimmable != 'false') { // WTF?
-							this.state.Brightness = device.dimLevel;
-							this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness)
-						}
+							if (device.dimmable != 'false') { // WTF?
+								this.state.Brightness = device.dimLevel;
+								this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness)
+							}
 
-						break
+							break
+						}
 					}
 				}
 			})
@@ -121,7 +123,7 @@ export class klikAanKlikUitAccessory extends accessory {
 		this.state.On = value as boolean
 
 		// http://$domoticaIP/external/WebUpdate.php?data=KlikAanKlikUit/$id/$state/
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
 			.catch((error) => {
 				this.platform.log.debug('klikAanKlikUitAccessory::setOn Error ->' + error)
 			})
@@ -135,7 +137,7 @@ export class klikAanKlikUitAccessory extends accessory {
 		this.state.Brightness = value as number
 
 		// http://$domoticaIP/external/WebUpdate.php?data=KlikAanKlikUit/$id/$state/$dimLevel
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '//' + this.state.Brightness)
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '//' + this.state.Brightness)
 			.catch((error) => {
 				this.platform.log.debug('klikAanKlikUitAccessory::setBrightness Error ->' + error)
 			})

+ 13 - 10
motionSensorAccessory.ts

@@ -87,16 +87,19 @@ export class motionSensorAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.motion) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.state == 'absent') {
-							this.state.Motion = false
-						} else { // present
-							this.state.Motion = true	
+				if (devices.hasOwnProperty('motion')) {
+					for (const device of devices.motion) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.state == 'absent') {
+								this.state.Motion = false
+							} else { // present
+								this.state.Motion = true	
+							}
+
+							this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
+
+							break
 						}
-						return this.state.Motion
-						this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
-						break
 					}
 				}
 			})
@@ -108,4 +111,4 @@ export class motionSensorAccessory extends accessory {
 	getState(): CharacteristicValue {
 		return this.state.Motion
 	}
-}
+}

+ 11 - 9
powerSocketAccessory.ts

@@ -94,15 +94,17 @@ export class powerSocketAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.powersocket) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.state == 'on') {
-							this.state.On = true
-						} else {
-							this.state.On = false
+				if (devices.hasOwnProperty('powersocket')) {
+					for (const device of devices.powersocket) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.state == 'on') {
+								this.state.On = true
+							} else {
+								this.state.On = false
+							}
+							this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
+							break
 						}
-						this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
-						break
 					}
 				}
 			})
@@ -115,7 +117,7 @@ export class powerSocketAccessory extends accessory {
 		this.state.On = value as boolean
 
 		// http://$domoticaIP/external/WebUpdate.php?data=PowerSocket/$id/$state/
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSocket/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSocket/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
 			.catch((error) => {
 				this.platform.log.debug('powerSocketAccessory::setOn Error ->' + error)
 			})

+ 16 - 14
powerSwitchAccessory.ts

@@ -100,20 +100,22 @@ export class powerSwitchAccessory extends accessory {
 			.then((response) => {
 				const devices = JSON.parse(response.body)
 
-				for (const device of devices.powerswitch) {
-					if (device.id == this.accessory.context.device.typeId) {
-						if (device.state == 'on') {
-							this.state.On = true
-						} else {
-							this.state.On = false
-						}
-						this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
+				if (devices.hasOwnProperty('powerswitch')) {
+					for (const device of devices.powerswitch) {
+						if (device.id == this.accessory.context.device.typeId) {
+							if (device.state == 'on') {
+								this.state.On = true
+							} else {
+								this.state.On = false
+							}
+							this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On)
 
-						if (device.dimmable != 'false') { // WTF?
-							this.state.Brightness = device.dimlevel;
-							this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness)
+							if (device.dimmable != 'false') { // WTF?
+								this.state.Brightness = device.dimlevel;
+								this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness)
+							}
+							break
 						}
-						break
 					}
 				}
 			})
@@ -126,7 +128,7 @@ export class powerSwitchAccessory extends accessory {
 		this.state.On = value as boolean
 
 		// http://$domoticaIP/external/WebUpdate.php?data=PowerSwitch/$id/$state/
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/')
 			.catch((error) => {
 				this.platform.log.debug('powerSwitchAccessory::setOn Error ->' + error)
 			})
@@ -140,7 +142,7 @@ export class powerSwitchAccessory extends accessory {
 		this.state.Brightness = value as number
 
 		// http://$domoticaIP/external/WebUpdate.php?data=PowerSwitch/$id/$state/$dimLevel
-		httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '//' + this.state.Brightness)
+		httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '///' + this.state.Brightness)
 			.catch((error) => {
 				this.platform.log.debug('powerSwitchAccessory::setBrightness Error ->' + error)
 			})