- Added detailed comments to clarify the purpose of various functions and types in the Discord bot and HA gateway. - Introduced new methods in the CommandApp for handling light and switch operations, including HandleLightOn, HandleLightOff, HandleLightToggle, and their respective autocomplete functions. - Updated the HAClient interface to include methods for fetching states and calling services, enhancing the interaction with Home Assistant. - Improved the structure of entity and light domain models to include additional attributes and clearer documentation. - Implemented logging enhancements in both the Discord bot and HA gateway to ensure better traceability and context in logs. - Refactored the configuration loading process to streamline environment variable handling and defaults. - Stubbed out switch control methods in the gRPC adapter, indicating future implementation plans. - Enhanced telemetry setup to ensure proper initialization and shutdown procedures for observability.
50 lines
1.8 KiB
Go
50 lines
1.8 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
|
|
}
|
|
|
|
// NewSwitchGRPC constructs the gRPC adapter for SwitchService.
|
|
func NewSwitchGRPC(svc driving.SwitchService) *SwitchGRPC {
|
|
return &SwitchGRPC{svc: svc}
|
|
}
|
|
|
|
// ListSwitches returns discovery-oriented switch metadata for clients.
|
|
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 is stubbed until switch control orchestration exists in the app layer.
|
|
// TODO: implement switch control RPCs — see plan.md for context
|
|
func (h *SwitchGRPC) TurnOn(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
|
|
return nil, grpcError(ErrNotImplemented)
|
|
}
|
|
|
|
// TurnOff is stubbed until switch control orchestration exists in the app layer.
|
|
// TODO: implement switch control RPCs — see plan.md for context
|
|
func (h *SwitchGRPC) TurnOff(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
|
|
return nil, grpcError(ErrNotImplemented)
|
|
}
|
|
|
|
// Toggle is stubbed until switch control orchestration exists in the app layer.
|
|
// TODO: implement switch control RPCs — see plan.md for context
|
|
func (h *SwitchGRPC) Toggle(ctx context.Context, req *hav1.SwitchRequest) (*hav1.SwitchResponse, error) {
|
|
return nil, grpcError(ErrNotImplemented)
|
|
}
|