package grpc import ( "context" hav1 "gitea.nik4nao.com/nik/home-services/gen/ha/v1" "gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/domain" "gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/ports/driving" ) type LightGRPC struct { hav1.UnimplementedLightServiceServer svc driving.LightService } func NewLightGRPC(svc driving.LightService) *LightGRPC { return &LightGRPC{svc: svc} } func (h *LightGRPC) TurnOn(ctx context.Context, req *hav1.TurnOnRequest) (*hav1.LightResponse, error) { s, err := h.svc.TurnOn(ctx, protoTurnOnToParams(req)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } func (h *LightGRPC) TurnOff(ctx context.Context, req *hav1.TurnOffRequest) (*hav1.LightResponse, error) { s, err := h.svc.TurnOff(ctx, protoTurnOffToParams(req)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } func (h *LightGRPC) Toggle(ctx context.Context, req *hav1.ToggleRequest) (*hav1.LightResponse, error) { s, err := h.svc.Toggle(ctx, domain.EntityID(req.EntityId)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } func (h *LightGRPC) ListLights(ctx context.Context, req *hav1.ListLightsRequest) (*hav1.ListLightsResponse, error) { lights, err := h.svc.ListLights(ctx) if err != nil { return nil, grpcError(err) } out := make([]*hav1.LightEntity, 0, len(lights)) for _, l := range lights { out = append(out, domainLightToProto(l)) } return &hav1.ListLightsResponse{Lights: out}, nil }