- Added ListSwitches method to SwitchService in switch_grpc.pb.go. - Implemented SwitchGRPC adapter for ListSwitches in switch.go. - Created SwitchApp for managing switch states and added ListSwitches logic. - Updated core domain with Switch struct and associated methods. - Enhanced LightApp to include ListLights functionality. - Updated protobuf definitions for Switch and Light services to include new request and response messages. - Introduced error handling for unimplemented methods in the gRPC server.
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package grpc
|
|
|
|
import (
|
|
hav1 "gitea.nik4nao.com/nik/home-services/gen/ha/v1"
|
|
"gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/domain"
|
|
)
|
|
|
|
func domainStateToProto(s *domain.EntityState) *hav1.EntityState {
|
|
return &hav1.EntityState{
|
|
EntityId: string(s.EntityID),
|
|
State: s.State,
|
|
Attributes: s.Attributes,
|
|
LastChanged: s.LastChanged.Format("2006-01-02T15:04:05Z07:00"),
|
|
LastUpdated: s.LastUpdated.Format("2006-01-02T15:04:05Z07:00"),
|
|
}
|
|
}
|
|
|
|
func protoTurnOnToParams(r *hav1.TurnOnRequest) domain.TurnOnParams {
|
|
p := domain.TurnOnParams{
|
|
EntityID: domain.EntityID(r.EntityId),
|
|
}
|
|
if r.BrightnessPct != nil {
|
|
v := r.GetBrightnessPct()
|
|
p.BrightnessPct = &v
|
|
}
|
|
if r.ColorTempKelvin != nil {
|
|
v := r.GetColorTempKelvin()
|
|
p.ColorTempKelvin = &v
|
|
}
|
|
if r.RgbColor != nil {
|
|
p.RGBColor = &domain.RGBColor{
|
|
R: uint8(r.RgbColor.R),
|
|
G: uint8(r.RgbColor.G),
|
|
B: uint8(r.RgbColor.B),
|
|
}
|
|
}
|
|
if r.Transition != nil {
|
|
v := r.GetTransition()
|
|
p.Transition = &v
|
|
}
|
|
return p
|
|
}
|
|
|
|
func protoTurnOffToParams(r *hav1.TurnOffRequest) domain.TurnOffParams {
|
|
p := domain.TurnOffParams{
|
|
EntityID: domain.EntityID(r.EntityId),
|
|
}
|
|
if r.Transition != nil {
|
|
v := r.GetTransition()
|
|
p.Transition = &v
|
|
}
|
|
return p
|
|
}
|
|
|
|
func domainLightToProto(l domain.Light) *hav1.LightEntity {
|
|
modes := make([]string, len(l.SupportedColorModes))
|
|
for i, m := range l.SupportedColorModes {
|
|
modes[i] = string(m)
|
|
}
|
|
return &hav1.LightEntity{
|
|
EntityId: string(l.EntityID),
|
|
FriendlyName: l.FriendlyName,
|
|
State: l.State,
|
|
SupportedColorModes: modes,
|
|
MinColorTempKelvin: l.MinColorTempKelvin,
|
|
MaxColorTempKelvin: l.MaxColorTempKelvin,
|
|
IsHueGroup: l.IsHueGroup,
|
|
EffectList: l.EffectList,
|
|
}
|
|
}
|
|
|
|
func domainSwitchToProto(s domain.Switch) *hav1.SwitchEntity {
|
|
return &hav1.SwitchEntity{
|
|
EntityId: string(s.EntityID),
|
|
FriendlyName: s.FriendlyName,
|
|
State: s.State,
|
|
DeviceClass: s.DeviceClass,
|
|
}
|
|
}
|