1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Darko Draskovic 19503742a6
NOISSUE - Update state based on SenML time value (#1075)
* Update state based on SenML time value

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Use Modf to parse SenML rec time

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Add Update to State in mocks

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Add Delta to Twin Definition and iota consts for state actions

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Use action consts for switch statement

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
2020-03-18 19:56:39 +01:00

84 lines
2.3 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package twins
import (
"context"
"time"
)
// Metadata stores arbitrary twin data
type Metadata map[string]interface{}
// Attribute stores individual attribute data
type Attribute struct {
Name string `json:"name"`
Channel string `json:"channel"`
Subtopic string `json:"subtopic"`
PersistState bool `json:"persist_state"`
}
// Definition stores entity's attributes
type Definition struct {
ID int `json:"id"`
Created time.Time `json:"created"`
Attributes []Attribute `json:"attributes"`
Delta int64 `json:"delta"`
}
// Twin represents a Mainflux thing digital twin. Each twin is owned by one thing, and
// is assigned with the unique identifier.
type Twin struct {
Owner string
ID string
Name string
ThingID string
Created time.Time
Updated time.Time
Revision int
Definitions []Definition
Metadata Metadata
}
// PageMetadata contains page metadata that helps navigation.
type PageMetadata struct {
Total uint64
Offset uint64
Limit uint64
Name string
}
// TwinsPage contains page related metadata as well as a list of twins that
// belong to this page.
type TwinsPage struct {
PageMetadata
Twins []Twin
}
// TwinRepository specifies a twin persistence API.
type TwinRepository interface {
// Save persists the twin
Save(context.Context, Twin) (string, error)
// Update performs an update to the existing twin. A non-nil error is
// returned to indicate operation failure.
Update(context.Context, Twin) error
// RetrieveByID retrieves the twin having the provided identifier.
RetrieveByID(ctx context.Context, id string) (Twin, error)
// RetrieveByAttribute retrieves twin ids whose definition contains
// the attribute with given channel and subtopic
RetrieveByAttribute(ctx context.Context, channel, subtopic string) ([]string, error)
// RetrieveAll retrieves the subset of things owned by the specified user.
RetrieveAll(context.Context, string, uint64, uint64, string, Metadata) (TwinsPage, error)
// RetrieveByThing retrieves twin that represents specified thing
RetrieveByThing(context.Context, string) (Twin, error)
// Remove removes the twin having the provided identifier.
Remove(ctx context.Context, id string) error
}