Skip to content

Commit 8dba186

Browse files
committed
Tidy up aframe demo
1 parent a5f1d1a commit 8dba186

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

demo-aframe/aframe-demo.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ AFRAME.registerComponent('homie-light-switch', {
3131
toggleSwitch: function () {
3232
this.switchState = !this.switchState;
3333
this.stateProperty.setValue(this.switchState);
34+
const bulbComponent = document.querySelector('#bulb').components["homie-light-bulb"].updateBulbState(this.switchState);
3435
this.updateSwitchVisual();
3536
},
3637

@@ -92,18 +93,11 @@ observer.updated$.subscribe(
9293
if (event.type == 'property') {
9394
if (event.device.id === 'switch' && event.node.id === 'switch' && event.property.id === 'state') {
9495
document.getElementById('switch-state').textContent = `Switch State: ${event.property.value}`;
95-
const switchComponent = document.querySelector('[homie-light-switch]').components["homie-light-switch"];
96+
const switchComponent = document.querySelector('#switch').components["homie-light-switch"];
9697
switchComponent.toggleSwitch();
9798
switchComponent.updateSwitchVisual();
98-
const bulbComponent = document.querySelector('[homie-light-bulb]').components["homie-light-bulb"];
99-
bulbComponent.updateBulbState(event.property.value=='true');
99+
100100
}
101-
// else if (event.device.id === 'bulb' && event.node.id === 'bulb' && event.property.id === 'state') {
102-
// document.getElementById('bulb-state').textContent = `Bulb State: ${event.property.value}`;
103-
// // Update the bulb entity in A-Frame
104-
// const bulbComponent = document.querySelector('[homie-light-bulb]').components["homie-light-bulb"];
105-
// bulbComponent.updateBulbState(event.property.value=='true');
106-
// }
107101
}
108102
},
109103
(error) => {
@@ -114,5 +108,3 @@ observer.updated$.subscribe(
114108

115109

116110
observer.subscribe('switch/switch/state');
117-
// observer.subscribe('bulb/bulb/state');
118-

demo-aframe/index.html

+3-14
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,13 @@ <h1>Homie-Lit A-Frame Demo</h1>
3737
</a-entity>
3838
</a-camera>
3939

40-
<a-entity homie-light-switch position="-1 0.5 -3" rotation="0 30 0"></a-entity>
41-
<a-entity homie-light-bulb position="1 0.5 -3" rotation="0 -30 0"></a-entity>
40+
<a-entity id="switch" homie-light-switch position="-1 0.5 -3" rotation="0 30 0"></a-entity>
41+
<a-entity id="bulb" homie-light-bulb position="1 0.5 -3" rotation="0 -30 0"></a-entity>
4242

4343
<a-entity light="type: ambient; color: #BBB"></a-entity>
4444
<a-sky color="#ECECEC"></a-sky>
4545
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
4646
</a-scene>
47-
<script>
48-
// Connect devices after scene loaded
49-
document.querySelector('a-scene').addEventListener('loaded', function () {
50-
const switchDevice = document.querySelector('[homie-light-switch]').components['homie-light-switch'].device;
51-
const bulbDevice = document.querySelector('[homie-light-bulb]').components['homie-light-bulb'].device;
52-
53-
// // Connect switch state to bulb state
54-
// switchDevice.getNode('switch').getProperty('state').on('value', (value) => {
55-
// bulbDevice.getNode('bulb').getProperty('state').setValue(value);
56-
// });
57-
});
58-
</script>
47+
5948
</body>
6049
</html>

0 commit comments

Comments
 (0)