@@ -38,6 +38,12 @@ class ExposedThing implements scripting_api.ExposedThing, ExposableThing {
3838
3939 final Map <String , scripting_api.ActionHandler > _actionHandlers = {};
4040
41+ final Map <String , scripting_api.EventSubscriptionHandler >
42+ _eventSubscribeHandlers = {};
43+
44+ final Map <String , scripting_api.EventSubscriptionHandler >
45+ _eventUnsubscribeHandlers = {};
46+
4147 Property _obtainProperty (String name) {
4248 final property = thingDescription.properties? [name];
4349
@@ -152,15 +158,23 @@ class ExposedThing implements scripting_api.ExposedThing, ExposableThing {
152158 String name,
153159 scripting_api.EventSubscriptionHandler handler,
154160 ) {
155- // TODO(JKRhb): implement setEventSubscribeHandler
161+ if (thingDescription.events? [name] == null ) {
162+ throw ArgumentError ("ExposedThing does not an Event with the key $name " );
163+ }
164+
165+ _eventSubscribeHandlers[name] = handler;
156166 }
157167
158168 @override
159169 void setEventUnsubscribeHandler (
160170 String name,
161171 scripting_api.EventSubscriptionHandler handler,
162172 ) {
163- // TODO(JKRhb): implement setEventUnsubscribeHandler
173+ if (thingDescription.events? [name] == null ) {
174+ throw ArgumentError ("ExposedThing does not an Event with the key $name " );
175+ }
176+
177+ _eventUnsubscribeHandlers[name] = handler;
164178 }
165179
166180 @override
@@ -212,11 +226,11 @@ class ExposedThing implements scripting_api.ExposedThing, ExposableThing {
212226
213227 if (formIndex == null ) {
214228 // FIXME: Returning a form does not really make sense here.
215- form = Form (Uri . parse ( "hi" ));
229+ form = Form (Uri ( ));
216230 } else {
217231 form = thingDescription.properties? [propertyName]? .forms
218232 .elementAtOrNull (formIndex) ??
219- Form (Uri . parse ( "hi" ));
233+ Form (Uri ( ));
220234 }
221235
222236 await writeHandler (
0 commit comments