func (o *DefaultThingManager) Handle(thing *api.Thing, service *api.ThingService, state api.State) { facts := new(api.RuleFacts) facts.Thing = thing facts.Service = service facts.Target = thing.GetId() drv := o.factory.CreateThingAdapter(thing.Descriptor.TypeId) // Save latest state of thing if state != nil { state["lastUpdated"] = time.Now() o.dataSource.SaveState(thing, state) } // Save event to DB desc := thing.Descriptor if desc.LogEvents { evt := api.NewEvent() evt.Thing = thing.Id evt.Service = service.Name evt.ShortText, evt.LongText = drv.GetEventText(thing, service, state) evt.Event = api.EVENT_SENSE evt.Data = state o.dataSource.PutEvent(evt) } // Run Rules for this thing o.rulesService.Trigger(api.TRIGGER_THING, facts) }
func (o *DefaultThingManager) RegisterThing(d api.Thing) { descriptor, err := o.GetThingType(d.Type) if err != nil { log.Println(err) } d.Descriptor = descriptor o.things[d.GetId()] = d }
func (o *DefaultThingManager) SaveThing(d api.Thing) { go o.dataSource.SaveThing(d) o.things[d.GetId()] = d }