Skip to content

Commit

Permalink
Fix up remaining faults after rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 25, 2024
1 parent 2ba6d2e commit 397682a
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 259 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: test

on: [push]
on: [ push ]
jobs:

build:
name: Build
runs-on: ubuntu-20.04
steps:

- name: Set up Go 1.22
uses: actions/setup-go@v2
with:
stable: 'false'
go-version: 1.22
id: go
- name: Set up Go 1.22
uses: actions/setup-go@v2
with:
stable: 'false'
go-version: 1.22
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
submodules: true
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
submodules: true

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
run: go test -v .
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
run: go test -v .
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg)](https://github.com/RichardLitt/standard-readme)
[![Actions Status](https://github.com/shimmeringbee/controller/workflows/test/badge.svg)](https://github.com/shimmeringbee/controller/actions)

> Implementation of home automation controller (a.k.a hub and gateway), initially focusing on Zigbee devices, written in Go.
> Implementation of home automation controller (a.k.a hub and gateway), initially focusing on Zigbee devices, written in
> Go.
## Table of Contents

Expand All @@ -17,7 +18,8 @@

## Background

The Shimmering Bee Controller is an implementation of a home automation controller, initially focusing on Zigbee to interact with real world devices.
The Shimmering Bee Controller is an implementation of a home automation controller, initially focusing on Zigbee to
interact with real world devices.

## Developing

Expand All @@ -40,20 +42,21 @@ This piece of software is not ready for general use.

Feel free to dive in! [Open an issue](https://github.com/shimmeringbee/controller/issues/new) or submit PRs.

All Shimmering Bee projects follow the [Contributor Covenant](https://shimmeringbee.io/docs/code_of_conduct/) Code of Conduct.
All Shimmering Bee projects follow the [Contributor Covenant](https://shimmeringbee.io/docs/code_of_conduct/) Code of
Conduct.

## License

Copyright 2019-2020 Shimmering Bee Contributors
Copyright 2019-2020 Shimmering Bee Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
19 changes: 10 additions & 9 deletions interface/converters/exporter/device_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,20 @@ func TestDeviceExporter_ExportSimpleDevice(t *testing.T) {
mockCapOne := mocks.BasicCapability{}
defer mockCapOne.AssertExpectations(t)
mockCapOne.On("Name").Return("capOne")
mgwOne.On("Capability", capOne).Return(&mockCapOne)

do := state.NewDeviceOrganiser(state.NullEventPublisher)
do := state.NewDeviceOrganiser(memory.New(), state.NullEventPublisher)
do.NewZone("one")
do.AddDevice("one-one")
do.NameDevice("one-one", "fancyname")
do.AddDeviceToZone("one-one", 1)

input := da.BaseDevice{
DeviceGateway: &mgwOne,
DeviceIdentifier: SimpleIdentifier{id: "one-one"},
DeviceCapabilities: []da.Capability{capOne},
}
mdev := &mocks.MockDevice{}
defer mdev.AssertExpectations(t)

mdev.On("Identifier").Return(SimpleIdentifier{id: "one-one"})
mdev.On("Capabilities").Return([]da.Capability{capOne})
mdev.On("Capability", capOne).Return(&mockCapOne)
mdev.On("Gateway").Return(&mgwOne)

expected := ExportedSimpleDevice{
Identifier: "one-one",
Expand All @@ -108,10 +109,10 @@ func TestDeviceExporter_ExportSimpleDevice(t *testing.T) {
mgm := state.MockGatewayMapper{}
defer mgm.AssertExpectations(t)

mgm.On("GatewayName", mock.Anything).Return("gw", true)
mgm.On("GatewayName", &mgwOne).Return("gw", true)

dc := DeviceExporter{DeviceOrganiser: &do, GatewayMapper: &mgm}
actual := dc.ExportSimpleDevice(context.Background(), input)
actual := dc.ExportSimpleDevice(context.Background(), mdev)

assert.Equal(t, expected, actual)
})
Expand Down
4 changes: 2 additions & 2 deletions interface/converters/exporter/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (m *MockDeviceExporter) ExportSimpleDevice(ctx context.Context, daDevice da
return args.Get(0).(ExportedSimpleDevice)
}

func (m *MockDeviceExporter) ExportCapability(ctx context.Context, daDevice da.Device, e interface{}) interface{} {
args := m.Called(ctx, daDevice, e)
func (m *MockDeviceExporter) ExportCapability(ctx context.Context, e interface{}) interface{} {
args := m.Called(ctx, e)
return args.Get(0)
}

Expand Down
2 changes: 1 addition & 1 deletion interface/http/v1/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DefaultHttpOutputLayer string = "http"
type deviceExporter interface {
ExportDevice(context.Context, da.Device) exporter.ExportedDevice
ExportSimpleDevice(context.Context, da.Device) exporter.ExportedSimpleDevice
ExportCapability(context.Context, da.Device, interface{}) interface{}
ExportCapability(context.Context, interface{}) interface{}
}

type deviceController struct {
Expand Down
33 changes: 12 additions & 21 deletions interface/http/v1/websocket_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ func eventToCapability(v interface{}) (da.Device, da.Capability, bool) {
return e.Device, capabilities.AlarmSensorFlag, true
case capabilities.AlarmWarningDeviceUpdate:
return e.Device, capabilities.AlarmWarningDeviceFlag, true
case capabilities.ColorStatusUpdate:
return e.Device, capabilities.ColorFlag, true
case capabilities.DeviceDiscoveryEnabled:
return e.Gateway.Self(), capabilities.DeviceDiscoveryFlag, true
case capabilities.DeviceDiscoveryDisabled:
return e.Gateway.Self(), capabilities.DeviceDiscoveryFlag, true
case capabilities.EnumerateDeviceStart:
return e.Device, capabilities.EnumerateDeviceFlag, true
case capabilities.EnumerateDeviceFailure:
case capabilities.EnumerateDeviceStopped:
return e.Device, capabilities.EnumerateDeviceFlag, true
case capabilities.EnumerateDeviceSuccess:
return e.Device, capabilities.EnumerateDeviceFlag, true
case capabilities.IlluminationSensorState:
case capabilities.IlluminationSensorUpdate:
return e.Device, capabilities.IlluminationSensorFlag, true
case capabilities.LevelStatusUpdate:
return e.Device, capabilities.LevelFlag, true
case capabilities.LocalDebugStart:
return e.Device, capabilities.LocalDebugFlag, true
case capabilities.LocalDebugSuccess:
Expand All @@ -58,39 +52,36 @@ func eventToCapability(v interface{}) (da.Device, da.Capability, bool) {
return e.Device, capabilities.MessageCaptureDebugFlag, true
case capabilities.MessageCaptureStop:
return e.Device, capabilities.MessageCaptureDebugFlag, true
case capabilities.OccupancySensorState:
case capabilities.OccupancySensorUpdate:
return e.Device, capabilities.OccupancySensorFlag, true
case capabilities.OnOffState:
case capabilities.OnOffUpdate:
return e.Device, capabilities.OnOffFlag, true
case capabilities.PowerStatusUpdate:
return e.Device, capabilities.PowerSupplyFlag, true
case capabilities.PressureSensorState:
case capabilities.PressureSensorUpdate:
return e.Device, capabilities.PressureSensorFlag, true
case capabilities.RelativeHumiditySensorState:
case capabilities.RelativeHumiditySensorUpdate:
return e.Device, capabilities.RelativeHumiditySensorFlag, true
case capabilities.RemoteDebugStart:
return e.Device, capabilities.RemoteDebugFlag, true
case capabilities.RemoteDebugSuccess:
return e.Device, capabilities.RemoteDebugFlag, true
case capabilities.RemoteDebugFailure:
return e.Device, capabilities.RemoteDebugFlag, true
case capabilities.TemperatureSensorState:
case capabilities.TemperatureSensorUpdate:
return e.Device, capabilities.TemperatureSensorFlag, true
default:
return da.BaseDevice{}, 0, false
return nil, 0, false
}
}

func (w websocketEventMapper) MapEvent(ctx context.Context, v interface{}) ([][]byte, error) {
switch e := v.(type) {
case da.DeviceAdded:
return w.generateDeviceMessages(ctx, e.Device), nil
case da.DeviceLoaded:
return w.generateDeviceMessages(ctx, e.Device), nil
case capabilities.EnumerateDeviceSuccess:
return w.generateDeviceMessages(ctx, e.Device), nil
case capabilities.EnumerateDeviceFailure:
case capabilities.EnumerateDeviceStopped:
return w.generateDeviceMessages(ctx, e.Device), nil

case da.DeviceRemoved:
return w.generateDeviceRemove(e.Device.Identifier())

Expand Down Expand Up @@ -219,14 +210,14 @@ func (w websocketEventMapper) generateDeviceUpdateMessage(ctx context.Context, d
}

func (w websocketEventMapper) generateDeviceUpdateCapabilityMessage(ctx context.Context, daDevice da.Device, capFlag da.Capability) ([][]byte, error) {
uncastCapability := daDevice.Gateway().Capability(capFlag)
uncastCapability := daDevice.Capability(capFlag)

basic, ok := uncastCapability.(da.BasicCapability)
if !ok {
return nil, nil
}

out := w.deviceExporter.ExportCapability(ctx, daDevice, uncastCapability)
out := w.deviceExporter.ExportCapability(ctx, uncastCapability)

data, err := json.Marshal(DeviceUpdateCapabilityMessage{
DeviceMessage: DeviceMessage{
Expand Down
Loading

0 comments on commit 397682a

Please sign in to comment.