Skip to content

Commit f50d480

Browse files
authored
Add HomeKit metadata editor (openhab#261)
Link to relevant docs on the supported third-party integrations using metadata Signed-off-by: Yannick Schaus <[email protected]>
1 parent 90ff071 commit f50d480

File tree

6 files changed

+267
-0
lines changed

6 files changed

+267
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
const accessories = {
2+
'LeakSensor': [
3+
'LeakDetectedState',
4+
'Name',
5+
'ActiveStatus',
6+
'FaultStatus',
7+
'TamperedStatus',
8+
'BatteryLowStatus'
9+
],
10+
'MotionSensor': [
11+
'MotionDetectedState',
12+
'Name',
13+
'ActiveStatus',
14+
'FaultStatus',
15+
'TamperedStatus',
16+
'BatteryLowStatus'
17+
],
18+
'OccupancySensor': [
19+
'OccupancyDetectedState',
20+
'Name',
21+
'ActiveStatus',
22+
'FaultStatus',
23+
'TamperedStatus',
24+
'BatteryLowStatus'
25+
],
26+
'ContactSensor': [
27+
'ContactSensorState',
28+
'Name',
29+
'ActiveStatus',
30+
'FaultStatus',
31+
'TamperedStatus',
32+
'BatteryLowStatus'
33+
],
34+
'SmokeSensor': [
35+
'SmokeDetectedState',
36+
'Name',
37+
'ActiveStatus',
38+
'FaultStatus',
39+
'TamperedStatus',
40+
'BatteryLowStatus'
41+
],
42+
'HumiditySensor': [
43+
'RelativeHumidity',
44+
'Name',
45+
'ActiveStatus',
46+
'FaultStatus',
47+
'TamperedStatus',
48+
'BatteryLowStatus'
49+
],
50+
'TemperatureSensor': [
51+
'CurrentTemperature',
52+
'Name',
53+
'ActiveStatus',
54+
'FaultStatus',
55+
'TamperedStatus',
56+
'BatteryLowStatus'
57+
],
58+
'CarbonDioxideSensor': [
59+
'CarbonDioxideDetectedState',
60+
'CarbonDioxideLevel',
61+
'CarbonDioxidePeakLevel',
62+
'Name',
63+
'ActiveStatus',
64+
'FaultStatus',
65+
'TamperedStatus',
66+
'BatteryLowStatus'
67+
],
68+
'CarbonMonoxideSensor': [
69+
'CarbonMonoxideDetectedState',
70+
'CarbonMonoxideLevel',
71+
'CarbonMonoxidePeakLevel',
72+
'Name',
73+
'ActiveStatus',
74+
'FaultStatus',
75+
'TamperedStatus',
76+
'BatteryLowStatus'
77+
],
78+
'WindowCovering': [
79+
'CurrentPosition',
80+
'TargetPosition',
81+
'PositionState',
82+
'Name',
83+
'HoldPosition',
84+
'ObstructionStatus',
85+
'CurrentHorizontalTiltAngle',
86+
'TargetHorizontalTiltAngle',
87+
'CurrentVerticalTiltAngle',
88+
'TargetVerticalTiltAngle'
89+
],
90+
'Switchable': [
91+
'OnState',
92+
'Name'
93+
],
94+
'Outlet': [
95+
'OnState',
96+
'InUseStatus',
97+
'Name'
98+
],
99+
'Lighting': [
100+
'OnState',
101+
'Name',
102+
'Hue',
103+
'Saturation',
104+
'Brightness',
105+
'ColorTemperature'
106+
],
107+
'Fan': [
108+
'ActiveStatus',
109+
'CurrentFanState',
110+
'TargetFanState',
111+
'RotationDirection',
112+
'RotationSpeed',
113+
'SwingMode',
114+
'LockControl'
115+
],
116+
'Thermostat': [
117+
'CurrentTemperature',
118+
'TargetTemperature',
119+
'CurrentHeatingCoolingMode',
120+
'TargetHeatingCoolingMode'
121+
],
122+
'Lock': [
123+
'LockCurrentState',
124+
'LockTargetState',
125+
'Name'
126+
],
127+
'Valve': [
128+
'ActiveStatus',
129+
'InUseStatus',
130+
'Duration',
131+
'RemainingDuration',
132+
'Name',
133+
'FaultStatus'
134+
],
135+
'SecuritySystem': [
136+
'CurrentSecuritySystemState',
137+
'TargetSecuritySystemState',
138+
'Name',
139+
'FaultStatus',
140+
'TamperedStatus'
141+
],
142+
'GarageDoorOpener': [
143+
'ObstructionStatus',
144+
'CurrentDoorState',
145+
'TargetDoorState',
146+
'Name',
147+
'LockCurrentState',
148+
'LockTargetState'
149+
]
150+
}
151+
152+
export const accessoriesAndCharacteristics = []
153+
for (const a in accessories) {
154+
accessoriesAndCharacteristics.push(a)
155+
for (const c of accessories[a]) {
156+
accessoriesAndCharacteristics.push(a + '.' + c)
157+
}
158+
}
159+
160+
const valveTypeParameter = {
161+
name: 'homekitValveType',
162+
label: 'Valve Type',
163+
type: 'TEXT',
164+
limitToOptions: true,
165+
options: [
166+
{ value: 'Generic', label: 'Generic' },
167+
{ value: 'Irrigation', label: 'Irrigation' },
168+
{ value: 'Shower', label: 'Shower' },
169+
{ value: 'Faucet', label: 'Faucet' }
170+
]
171+
}
172+
173+
const valveTimerParameter = {
174+
name: 'homekitTimer',
175+
label: 'Timer',
176+
type: 'BOOLEAN'
177+
}
178+
179+
const valveDefaultDuration = {
180+
name: 'homekitDefaultDuration',
181+
label: 'Default Duration',
182+
type: 'INTEGER'
183+
}
184+
185+
export const homekitParameters = [valveTypeParameter, valveTimerParameter, valveDefaultDuration]

bundles/org.openhab.ui/web/src/assets/definitions/metadata/namespaces.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export default [
66
{ name: 'listWidget', label: 'Default List Item Widget' },
77
{ name: 'autoupdate', label: 'Auto-update' },
88
{ name: 'alexa', label: 'Amazon Alexa' },
9+
{ name: 'homekit', label: 'Apple HomeKit' },
910
{ name: 'ga', label: 'Google Assistant' }
1011
]

bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-alexa.vue

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<div>
2929
<config-sheet :parameterGroups="[]" :parameters="parameters" :configuration="metadata.config" />
3030
</div>
31+
<p class="padding">
32+
<f7-link color="blue" external target="_blank" href="https://www.openhab.org/docs/ecosystem/alexa/">Alexa Integration Documentation</f7-link>
33+
</p>
3134
</div>
3235
</template>
3336

bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-ga.vue

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<div>
1313
<config-sheet :parameterGroups="[]" :parameters="parameters" :configuration="metadata.config" />
1414
</div>
15+
<p class="padding">
16+
<f7-link color="blue" external target="_blank" href="https://www.openhab.org/docs/ecosystem/google-assistant/">Google Assistant Integration Documentation</f7-link>
17+
</p>
1518
</div>
1619
</template>
1720

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<div>
3+
<div style="text-align:right" class="padding-right">
4+
<label @click="toggleMultiple" style="cursor:pointer">Multiple</label> <f7-checkbox :checked="multiple" @change="toggleMultiple"></f7-checkbox>
5+
</div>
6+
<f7-list>
7+
<f7-list-item :key="classSelectKey"
8+
:title="(multiple) ? 'HomeKit Accessory/Charactistics' : 'HomeKit Accessory/Charactistic'" smart-select :smart-select-params="{ openIn: 'popup', searchbar: true, closeOnSelect: !multiple }" ref="classes">
9+
<select name="parameters" @change="updateClasses" :multiple="multiple">
10+
<option v-if="!multiple" value=""></option>
11+
<option v-for="cl in classesDefs.filter((c) => c.indexOf('label:') !== 0)"
12+
:value="cl" :key="cl"
13+
:selected="isSelected(cl)">
14+
{{cl}}
15+
</option>
16+
</select>
17+
</f7-list-item>
18+
</f7-list>
19+
<div>
20+
<config-sheet :parameterGroups="[]" :parameters="parameters" :configuration="metadata.config" />
21+
</div>
22+
<p class="padding">
23+
<f7-link color="blue" external target="_blank" href="https://www.openhab.org/addons/integrations/homekit/">HomeKit integration documentation</f7-link>
24+
</p>
25+
</div>
26+
</template>
27+
28+
<script>
29+
import { accessoriesAndCharacteristics, homekitParameters } from '@/assets/definitions/metadata/homekit'
30+
import ConfigSheet from '@/components/config/config-sheet.vue'
31+
32+
export default {
33+
props: ['itemName', 'metadata', 'namespace'],
34+
components: {
35+
ConfigSheet
36+
},
37+
data () {
38+
return {
39+
classesDefs: accessoriesAndCharacteristics,
40+
multiple: !!this.metadata.value && this.metadata.value.indexOf(',') > 0,
41+
classSelectKey: this.$f7.utils.id()
42+
}
43+
},
44+
computed: {
45+
classes () {
46+
if (!this.multiple) return this.metadata.value
47+
return (this.metadata.value) ? this.metadata.value.split(',') : []
48+
},
49+
parameters () {
50+
if (!this.classes) return []
51+
if (!this.multiple && this.classes.indexOf('Valve') === 0) return homekitParameters
52+
if (this.multiple && this.classes.some((c) => c.indexOf('Valve') === 0)) return homekitParameters
53+
return []
54+
}
55+
},
56+
methods: {
57+
isSelected (cl) {
58+
return (this.multiple) ? this.classes.indexOf(cl) >= 0 : this.classes === cl
59+
},
60+
toggleMultiple () {
61+
this.multiple = !this.multiple
62+
this.metadata.value = ''
63+
this.classSelectKey = this.$f7.utils.id()
64+
},
65+
updateClasses () {
66+
const value = this.$refs.classes.f7SmartSelect.getValue()
67+
this.metadata.value = (Array.isArray(value)) ? value.join(',') : value
68+
this.$set(this.metadata, 'config', {})
69+
}
70+
}
71+
}
72+
</script>

bundles/org.openhab.ui/web/src/pages/settings/items/metadata/item-metadata-edit.vue

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import ItemMetadataSynonyms from '@/components/item/metadata/item-metadata-synon
5858
import ItemMetadataWidget from '@/components/item/metadata/item-metadata-widget.vue'
5959
import ItemMetadataAutoUpdate from '@/components/item/metadata/item-metadata-autoupdate.vue'
6060
import ItemMetadataAlexa from '@/components/item/metadata/item-metadata-alexa.vue'
61+
import ItemMetadataHomeKit from '@/components/item/metadata/item-metadata-homekit.vue'
6162
import ItemMetadataGa from '@/components/item/metadata/item-metadata-ga.vue'
6263
6364
export default {
@@ -91,6 +92,8 @@ export default {
9192
return ItemMetadataAutoUpdate
9293
case 'alexa':
9394
return ItemMetadataAlexa
95+
case 'homekit':
96+
return ItemMetadataHomeKit
9497
case 'ga':
9598
return ItemMetadataGa
9699
default:

0 commit comments

Comments
 (0)