Nik Afiq abb6774b77 feat: implement SwitchService with ListSwitches method
- 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.
2026-04-06 19:25:06 +09:00

45 lines
1.4 KiB
Go

package grpc
import (
"context"
hav1 "gitea.nik4nao.com/nik/home-services/gen/ha/v1"
"gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/ports/driving"
)
type SwitchGRPC struct {
hav1.UnimplementedSwitchServiceServer
svc driving.SwitchService
}
func NewSwitchGRPC(svc driving.SwitchService) *SwitchGRPC {
return &SwitchGRPC{svc: svc}
}
func (h *SwitchGRPC) ListSwitches(ctx context.Context, req *hav1.ListSwitchesRequest) (*hav1.ListSwitchesResponse, error) {
switches, err := h.svc.ListSwitches(ctx)
if err != nil {
return nil, grpcError(err)
}
out := make([]*hav1.SwitchEntity, 0, len(switches))
for _, s := range switches {
out = append(out, domainSwitchToProto(s))
}
return &hav1.ListSwitchesResponse{Switches: out}, nil
}
// TurnOn, TurnOff, Toggle — left as Unimplemented for now.
// TODO: implement once app/switch.go has callService support.
// Follow the same pattern as LightGRPC: payload{"entity_id": ...} → ha.CallService.
func (h *SwitchGRPC) TurnOn(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
return nil, grpcError(ErrNotImplemented)
}
func (h *SwitchGRPC) TurnOff(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
return nil, grpcError(ErrNotImplemented)
}
func (h *SwitchGRPC) Toggle(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
return nil, grpcError(ErrNotImplemented)
}