lights

package
v0.32.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZoneState_name = map[int32]string{
		0: "ON",
		1: "OFF",
		2: "OFFTIMER",
		3: "COLOR",
		4: "RANDOMCOLOR",
		5: "NIGHTVISION",
		6: "EVENINGVISION",
		7: "MORNINGVISION",
	}
	ZoneState_value = map[string]int32{
		"ON":            0,
		"OFF":           1,
		"OFFTIMER":      2,
		"COLOR":         3,
		"RANDOMCOLOR":   4,
		"NIGHTVISION":   5,
		"EVENINGVISION": 6,
		"MORNINGVISION": 7,
	}
)

Enum value maps for ZoneState.

View Source
var (
	ColorTemperature_name = map[int32]string{
		0: "FIRSTLIGHT",
		1: "MORNING",
		2: "DAY",
		3: "LATEAFTERNOON",
		4: "EVENING",
	}
	ColorTemperature_value = map[string]int32{
		"FIRSTLIGHT":    0,
		"MORNING":       1,
		"DAY":           2,
		"LATEAFTERNOON": 3,
		"EVENING":       4,
	}
)

Enum value maps for ColorTemperature.

View Source
var (
	Brightness_name = map[int32]string{
		0: "FULL",
		1: "DIM",
		2: "LOW",
		3: "DIMPLUS",
		4: "LOWPLUS",
		5: "VERYLOW",
	}
	Brightness_value = map[string]int32{
		"FULL":    0,
		"DIM":     1,
		"LOW":     2,
		"DIMPLUS": 3,
		"LOWPLUS": 4,
		"VERYLOW": 5,
	}
)

Enum value maps for Brightness.

View Source
var ErrHandlerFailed = errors.New("handler failed")

ErrHandlerFailed is used to indicate that a lights handler has failed to execute.

View Source
var ErrNilConfig = errors.New("nil lights config")

ErrNilConfig is used to indicate that a method has received a config that was nil.

View Source
var ErrNoRoomsConfigured = errors.New("no rooms configured")

ErrNoRoomsConfigured is used to indicate that the configuration contained no Rooms.

View Source
var ErrRoomNotFound = errors.New("room not found")

ErrRoomNotFound is used to indicate a named room was not found in the config.

View Source
var ErrUnhandledEventName = errors.New("unhandled event name")

ErrUnhandledEventName is used to indicate the evet name was not found in the RoomConfig.

View Source
var ErrUnknownActionEvent = errors.New("unknown action event")

ErrUnknownActionEvent is used to indicate that an action was not recognized.

View Source
var File_modules_lights_lights_proto protoreflect.FileDescriptor
View Source
var Lights_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "lights.Lights",
	HandlerType: (*LightsServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "SetState",
			Handler:    _Lights_SetState_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "modules/lights/lights.proto",
}

Lights_ServiceDesc is the grpc.ServiceDesc for Lights service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func ParseHexColor

func ParseHexColor(s string) (c color.RGBA, err error)

func RegisterLightsServer

func RegisterLightsServer(s grpc.ServiceRegistrar, srv LightsServer)

Types

type Brightness

type Brightness int32
const (
	Brightness_FULL    Brightness = 0
	Brightness_DIM     Brightness = 1
	Brightness_LOW     Brightness = 2
	Brightness_DIMPLUS Brightness = 3
	Brightness_LOWPLUS Brightness = 4
	Brightness_VERYLOW Brightness = 5
)

func (Brightness) Descriptor

func (Brightness) Descriptor() protoreflect.EnumDescriptor

func (Brightness) Enum

func (x Brightness) Enum() *Brightness

func (Brightness) EnumDescriptor deprecated

func (Brightness) EnumDescriptor() ([]byte, []int)

Deprecated: Use Brightness.Descriptor instead.

func (Brightness) Number

func (x Brightness) Number() protoreflect.EnumNumber

func (Brightness) String

func (x Brightness) String() string

func (Brightness) Type

type ColorTempSchedule

type ColorTempSchedule map[ColorTemperature]time.Time

func (ColorTempSchedule) MostRecent

func (c ColorTempSchedule) MostRecent() ColorTemperature

type ColorTempSchedulerFunc

type ColorTempSchedulerFunc func() ColorTempSchedule

func StaticColorTempSchedule

func StaticColorTempSchedule(timezone string) (ColorTempSchedulerFunc, error)

type ColorTemperature

type ColorTemperature int32
const (
	ColorTemperature_FIRSTLIGHT    ColorTemperature = 0
	ColorTemperature_MORNING       ColorTemperature = 1
	ColorTemperature_DAY           ColorTemperature = 2
	ColorTemperature_LATEAFTERNOON ColorTemperature = 3
	ColorTemperature_EVENING       ColorTemperature = 4
)

func (ColorTemperature) Descriptor

func (ColorTemperature) Enum

func (ColorTemperature) EnumDescriptor deprecated

func (ColorTemperature) EnumDescriptor() ([]byte, []int)

Deprecated: Use ColorTemperature.Descriptor instead.

func (ColorTemperature) Number

func (ColorTemperature) String

func (x ColorTemperature) String() string

func (ColorTemperature) Type

type Config

type Config struct {
	Rooms       []Room   `yaml:"rooms"`
	PartyColors []string `yaml:"party_colors,omitempty"`
	TimeZone    string   `yaml:"timezone" json:"timezone"`
}

Config is the configuration for Lights

func (*Config) Room

func (c *Config) Room(name string) (Room, error)

Room return the Room object for a room given by name.

type Handler

type Handler interface {
	Alert(context.Context, string) error
	Off(context.Context, string) error
	On(context.Context, string) error
	RandomColor(context.Context, string, []string) error
	SetBrightness(context.Context, string, int32) error
	SetColor(context.Context, string, string) error
	SetColorTemp(context.Context, string, int32) error
	Toggle(context.Context, string) error
}

Handler is the interface to be implemented for a specific API.

func NewZigbeeLight

func NewZigbeeLight(cfg Config, mqttClient mqtt.Client, inv inventory.Inventory, logger log.Logger) (Handler, error)

type Light

type Light struct {
	Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Id   int32  `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	// contains filtered or unexported fields
}

func (*Light) Descriptor deprecated

func (*Light) Descriptor() ([]byte, []int)

Deprecated: Use Light.ProtoReflect.Descriptor instead.

func (*Light) GetId

func (x *Light) GetId() int32

func (*Light) GetName

func (x *Light) GetName() string

func (*Light) GetType

func (x *Light) GetType() string

func (*Light) ProtoMessage

func (*Light) ProtoMessage()

func (*Light) ProtoReflect

func (x *Light) ProtoReflect() protoreflect.Message

func (*Light) Reset

func (x *Light) Reset()

func (*Light) String

func (x *Light) String() string

type LightGroup

type LightGroup struct {
	Type   string  `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Id     int32   `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	Name   string  `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	Lights []int32 `protobuf:"varint,4,rep,packed,name=lights,proto3" json:"lights,omitempty"`
	// contains filtered or unexported fields
}

func (*LightGroup) Descriptor deprecated

func (*LightGroup) Descriptor() ([]byte, []int)

Deprecated: Use LightGroup.ProtoReflect.Descriptor instead.

func (*LightGroup) GetId

func (x *LightGroup) GetId() int32

func (*LightGroup) GetLights

func (x *LightGroup) GetLights() []int32

func (*LightGroup) GetName

func (x *LightGroup) GetName() string

func (*LightGroup) GetType

func (x *LightGroup) GetType() string

func (*LightGroup) ProtoMessage

func (*LightGroup) ProtoMessage()

func (*LightGroup) ProtoReflect

func (x *LightGroup) ProtoReflect() protoreflect.Message

func (*LightGroup) Reset

func (x *LightGroup) Reset()

func (*LightGroup) String

func (x *LightGroup) String() string

type LightResponse

type LightResponse struct {
	Lights []*Light      `protobuf:"bytes,1,rep,name=lights,proto3" json:"lights,omitempty"`
	Groups []*LightGroup `protobuf:"bytes,2,rep,name=groups,proto3" json:"groups,omitempty"`
	// contains filtered or unexported fields
}

func (*LightResponse) Descriptor deprecated

func (*LightResponse) Descriptor() ([]byte, []int)

Deprecated: Use LightResponse.ProtoReflect.Descriptor instead.

func (*LightResponse) GetGroups

func (x *LightResponse) GetGroups() []*LightGroup

func (*LightResponse) GetLights

func (x *LightResponse) GetLights() []*Light

func (*LightResponse) ProtoMessage

func (*LightResponse) ProtoMessage()

func (*LightResponse) ProtoReflect

func (x *LightResponse) ProtoReflect() protoreflect.Message

func (*LightResponse) Reset

func (x *LightResponse) Reset()

func (*LightResponse) String

func (x *LightResponse) String() string

type Lights

type Lights struct {
	UnimplementedLightsServer

	services.Service

	sync.Mutex
	// contains filtered or unexported fields
}

Lights holds the information necessary to communicate with lighting equipment, and the configuration to add a bit of context.

func New

func New(cfg Config, logger log.Logger) (*Lights, error)

NewLights creates and returns a new Lights object based on the received configuration.

func (*Lights) ActionHandler

func (l *Lights) ActionHandler(ctx context.Context, action *iot.Action) error

ActionHandler is called when an action is requested against a light group. The action speciefies the a button press and a room to give enough context for how to change the behavior of the lights in response to the action.

func (*Lights) AddHandler

func (l *Lights) AddHandler(h Handler)

AddHandler is used to register the received Handler.

func (*Lights) NamedTimerHandler

func (l *Lights) NamedTimerHandler(ctx context.Context, e string) error

func (*Lights) SetColorTempScheduler

func (l *Lights) SetColorTempScheduler(c ColorTempSchedulerFunc)

func (*Lights) SetRoomForEvent

func (l *Lights) SetRoomForEvent(ctx context.Context, event string) error

SetRoomForEvent is used to handle an event based on the room configuation.

type LightsClient

type LightsClient interface {
	SetState(ctx context.Context, in *ZoneStateRequest, opts ...grpc.CallOption) (*ZoneStateResponse, error)
}

LightsClient is the client API for Lights service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewLightsClient

func NewLightsClient(cc grpc.ClientConnInterface) LightsClient

type LightsServer

type LightsServer interface {
	SetState(context.Context, *ZoneStateRequest) (*ZoneStateResponse, error)
	// contains filtered or unexported methods
}

LightsServer is the server API for Lights service. All implementations must embed UnimplementedLightsServer for forward compatibility

type MockLight

type MockLight struct {
	AlertCalls         map[string]int
	OffCalls           map[string]int
	OnCalls            map[string]int
	RandomColorCalls   map[string]int
	SetBrightnessCalls map[string]int
	SetColorCalls      map[string]int
	SetColorTempCalls  map[string]int
	ToggleCalls        map[string]int
}

func (*MockLight) Alert

func (m *MockLight) Alert(ctx context.Context, groupName string) error

func (*MockLight) Off

func (m *MockLight) Off(ctx context.Context, groupName string) error

func (*MockLight) On

func (m *MockLight) On(ctx context.Context, groupName string) error

func (*MockLight) RandomColor

func (m *MockLight) RandomColor(ctx context.Context, groupName string, colors []string) error

func (*MockLight) SetBrightness

func (m *MockLight) SetBrightness(ctx context.Context, groupName string, brightness int32) error

func (*MockLight) SetColor

func (m *MockLight) SetColor(ctx context.Context, groupName string, hex string) error

func (*MockLight) SetColorTemp

func (m *MockLight) SetColorTemp(ctx context.Context, groupName string, temp int32) error

func (*MockLight) Toggle

func (m *MockLight) Toggle(ctx context.Context, groupName string) error

type Room

type Room struct {
	Name   string      `yaml:"name"`
	States []StateSpec `yaml:"states"`
}

Room is a collection of device entries.

type StateSpec

type StateSpec struct {
	State      ZoneState         `yaml:"state"`
	Brightness *Brightness       `yaml:"brightness,omitempty"`
	ColorTemp  *ColorTemperature `yaml:"color_temp,omitempty"`
	Event      string            `yaml:"event"`
}

func (*StateSpec) UnmarshalYAML

func (s *StateSpec) UnmarshalYAML(unmarshal func(interface{}) error) error

Implements the Unmarshaler interface of the yaml pkg.

type UnimplementedLightsServer

type UnimplementedLightsServer struct {
}

UnimplementedLightsServer must be embedded to have forward compatible implementations.

func (UnimplementedLightsServer) SetState

type UnsafeLightsServer

type UnsafeLightsServer interface {
	// contains filtered or unexported methods
}

UnsafeLightsServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to LightsServer will result in compilation errors.

type Zone

type Zone struct {
	// contains filtered or unexported fields
}

func NewZone

func NewZone(name string) *Zone

func (*Zone) Alert

func (z *Zone) Alert(ctx context.Context) error

func (*Zone) DecrementBrightness

func (z *Zone) DecrementBrightness(ctx context.Context) error

func (*Zone) Flush

func (z *Zone) Flush(ctx context.Context) error

Flush handles pushing the current state out to each of the hnadlers.

func (*Zone) IncrementBrightness

func (z *Zone) IncrementBrightness(ctx context.Context) error

func (*Zone) Name

func (z *Zone) Name() string

func (*Zone) Off

func (z *Zone) Off(ctx context.Context) error

func (*Zone) On

func (z *Zone) On(ctx context.Context) error

func (*Zone) RandomColor

func (z *Zone) RandomColor(ctx context.Context, colors []string) error

func (*Zone) SetBrightness

func (z *Zone) SetBrightness(ctx context.Context, brightness Brightness) error

func (*Zone) SetBrightnessMap

func (z *Zone) SetBrightnessMap(m map[Brightness]int32)

func (*Zone) SetColor

func (z *Zone) SetColor(ctx context.Context, color string) error

func (*Zone) SetColorTemperature

func (z *Zone) SetColorTemperature(ctx context.Context, colorTemp ColorTemperature) error

func (*Zone) SetColorTemperatureMap

func (z *Zone) SetColorTemperatureMap(m map[ColorTemperature]int32)

func (*Zone) SetHandlers

func (z *Zone) SetHandlers(handlers ...Handler)

func (*Zone) SetName

func (z *Zone) SetName(name string)

func (*Zone) SetState

func (z *Zone) SetState(ctx context.Context, state ZoneState) error

func (*Zone) Toggle

func (z *Zone) Toggle(ctx context.Context) error

type ZoneState

type ZoneState int32
const (
	ZoneState_ON          ZoneState = 0
	ZoneState_OFF         ZoneState = 1
	ZoneState_OFFTIMER    ZoneState = 2
	ZoneState_COLOR       ZoneState = 3
	ZoneState_RANDOMCOLOR ZoneState = 4 // DIM = 5;
	// //
	ZoneState_NIGHTVISION   ZoneState = 5
	ZoneState_EVENINGVISION ZoneState = 6
	ZoneState_MORNINGVISION ZoneState = 7
)

func (ZoneState) Descriptor

func (ZoneState) Descriptor() protoreflect.EnumDescriptor

func (ZoneState) Enum

func (x ZoneState) Enum() *ZoneState

func (ZoneState) EnumDescriptor deprecated

func (ZoneState) EnumDescriptor() ([]byte, []int)

Deprecated: Use ZoneState.Descriptor instead.

func (ZoneState) Number

func (x ZoneState) Number() protoreflect.EnumNumber

func (ZoneState) String

func (x ZoneState) String() string

func (ZoneState) Type

type ZoneStateRequest

type ZoneStateRequest struct {
	Name  string    `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	State ZoneState `protobuf:"varint,2,opt,name=state,proto3,enum=lights.ZoneState" json:"state,omitempty"`
	// contains filtered or unexported fields
}

func (*ZoneStateRequest) Descriptor deprecated

func (*ZoneStateRequest) Descriptor() ([]byte, []int)

Deprecated: Use ZoneStateRequest.ProtoReflect.Descriptor instead.

func (*ZoneStateRequest) GetName

func (x *ZoneStateRequest) GetName() string

func (*ZoneStateRequest) GetState

func (x *ZoneStateRequest) GetState() ZoneState

func (*ZoneStateRequest) ProtoMessage

func (*ZoneStateRequest) ProtoMessage()

func (*ZoneStateRequest) ProtoReflect

func (x *ZoneStateRequest) ProtoReflect() protoreflect.Message

func (*ZoneStateRequest) Reset

func (x *ZoneStateRequest) Reset()

func (*ZoneStateRequest) String

func (x *ZoneStateRequest) String() string

type ZoneStateResponse

type ZoneStateResponse struct {
	Color string `protobuf:"bytes,1,opt,name=color,proto3" json:"color,omitempty"`
	// contains filtered or unexported fields
}

func (*ZoneStateResponse) Descriptor deprecated

func (*ZoneStateResponse) Descriptor() ([]byte, []int)

Deprecated: Use ZoneStateResponse.ProtoReflect.Descriptor instead.

func (*ZoneStateResponse) GetColor

func (x *ZoneStateResponse) GetColor() string

func (*ZoneStateResponse) ProtoMessage

func (*ZoneStateResponse) ProtoMessage()

func (*ZoneStateResponse) ProtoReflect

func (x *ZoneStateResponse) ProtoReflect() protoreflect.Message

func (*ZoneStateResponse) Reset

func (x *ZoneStateResponse) Reset()

func (*ZoneStateResponse) String

func (x *ZoneStateResponse) String() string

type Zones

type Zones struct {
	// contains filtered or unexported fields
}

func (*Zones) GetZone

func (z *Zones) GetZone(name string) *Zone

func (*Zones) GetZones

func (z *Zones) GetZones() []*Zone

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL