Skip to content

Commit

Permalink
fix: Fix lint errors and introduce lint in action
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed Sep 30, 2023
1 parent afb0c95 commit f50a0f4
Show file tree
Hide file tree
Showing 36 changed files with 500 additions and 342 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lint

on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV

- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run linters
run: make lint
32 changes: 0 additions & 32 deletions .github/workflows/main.yml → .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
# - name: Extract Docker metadata
# id: meta
# uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build docker images
run: make docker-build -e IMG_TAG=${GITHUB_REF#refs/heads/}

Expand All @@ -68,27 +60,3 @@ jobs:

- name: Create & Push docker manifrst
run: make docker-manifest -e IMG_TAG=${GITHUB_REF#refs/heads/}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
# - name: Build and push Docker image
# id: build-and-push
# uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
# with:
# context: .
# file: build/Dockerfile.multistage
# platforms: linux/amd64,linux/arm64
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
# build-args: |
# GO_VERSION=${{ env.GO_VERSION }}

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GH_PAT }}
default_bump: false
34 changes: 25 additions & 9 deletions pkg/client/deconzclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *DeconzClient) handleSetDriverUserData(user_data map[string]string, conf

if err != nil {
log.WithError(err).Debug("Failed to get new api Key")
c.IntegrationDriver.SetDriverSetupState(integration.StopEvent, integration.ErrorDeviceState, integration.AuthErrorError, nil)
c.IntegrationDriver.SetDriverSetupState(integration.StopEvent, integration.ErrorState, integration.AuthErrorError, nil)
return
}

Expand Down Expand Up @@ -232,7 +232,9 @@ func (c *DeconzClient) handleNewSensorDeviceDiscovered(device *deconz.DeconzDevi

})

c.IntegrationDriver.AddEntity(sensor)
if err := c.IntegrationDriver.AddEntity(sensor); err != nil {
log.WithError(err).Error("Cannot add entity")
}
}
}

Expand Down Expand Up @@ -357,7 +359,9 @@ func (c *DeconzClient) handleNewLightDeviceDiscovered(device *deconz.DeconzDevic

})

c.IntegrationDriver.AddEntity(light)
if err := c.IntegrationDriver.AddEntity(light); err != nil {
log.WithError(err).Error("Cannot add entity")
}
}

func (c *DeconzClient) handleNewGroupDeviceDiscovered(device *deconz.DeconzDevice) {
Expand Down Expand Up @@ -440,9 +444,13 @@ func (c *DeconzClient) handleNewGroupDeviceDiscovered(device *deconz.DeconzDevic

group.AddCommand(entities.ToggleLightEntityCommand, func(entity entities.LightEntity, params map[string]interface{}) int {
if device.IsOn() {
device.TurnOff()
if err := device.TurnOff(); err != nil {
return 404
}
} else {
device.TurnOn()
if err := device.TurnOn(); err != nil {
return 404
}
}
return 200
})
Expand Down Expand Up @@ -495,7 +503,9 @@ func (c *DeconzClient) handleNewGroupDeviceDiscovered(device *deconz.DeconzDevic

})

c.IntegrationDriver.AddEntity(group)
if err := c.IntegrationDriver.AddEntity(group); err != nil {
log.WithError(err).Error("Cannot add entity")
}
}

func (c *DeconzClient) handleNewDeviceDiscovered(device *deconz.DeconzDevice) {
Expand Down Expand Up @@ -527,11 +537,17 @@ func (c *DeconzClient) handleRemoveDevice(device *deconz.DeconzDevice) {

switch device.Type {
case deconz.SensorDeconzDeviceType:
c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("sensor%d", device.GetID()))
if err := c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("sensor%d", device.GetID())); err != nil {
log.WithError(err).Error("Cannot remove Entity")
}
case deconz.LightDeconzDeviceType:
c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("light%d", device.GetID()))
if err := c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("light%d", device.GetID())); err != nil {
log.WithError(err).Error("Cannot remove Entity")
}
case deconz.GroupDeconzDeviceType:
c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("group%d", device.GetID()))
if err := c.IntegrationDriver.RemoveEntityByID(fmt.Sprintf("group%d", device.GetID())); err != nil {
log.WithError(err).Error("Cannot remove Entity")
}
}

}
Expand Down
35 changes: 21 additions & 14 deletions pkg/client/denonavrclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,28 @@ func (c *DenonAVRClient) initDenonAVRClient() {
c.mediaPlayer.AddFeature(entities.UnmuteMediaPlayerEntityFeatures)
c.mediaPlayer.AddFeature(entities.MuteToggleMediaPlayerEntityFeatures)
c.mediaPlayer.AddFeature(entities.SelectSourceMediaPlayerEntityFeatures)
c.mediaPlayer.AddFeature(entities.SelectSoundModeMediaPlayerEntityCommand)
c.mediaPlayer.AddFeature(entities.SelectSoundModeMediaPlayerEntityFeatures)
c.mediaPlayer.AddFeature(entities.DPadMediaPlayerEntityFeatures)
c.IntegrationDriver.AddEntity(c.mediaPlayer)

if err := c.IntegrationDriver.AddEntity(c.mediaPlayer); err != nil {
log.WithError(err).Error("Cannot add Entity")
}

// Butons
c.moni1Button = entities.NewButtonEntity("moni1", entities.LanguageText{En: "Monitor Out 1"}, "")
c.IntegrationDriver.AddEntity(c.moni1Button)
if err := c.IntegrationDriver.AddEntity(c.moni1Button); err != nil {
log.WithError(err).Error("Cannot add Entity")
}

c.moni2Button = entities.NewButtonEntity("moni2", entities.LanguageText{En: "Monitor Out 2"}, "")
c.IntegrationDriver.AddEntity(c.moni2Button)
if err := c.IntegrationDriver.AddEntity(c.moni2Button); err != nil {
log.WithError(err).Error("Cannot add Entity")
}

c.moniAutoButton = entities.NewButtonEntity("moniauto", entities.LanguageText{En: "Monitor Out Auto"}, "")
c.IntegrationDriver.AddEntity(c.moniAutoButton)
if err := c.IntegrationDriver.AddEntity(c.moniAutoButton); err != nil {
log.WithError(err).Error("Cannot add Entity")
}

}

Expand Down Expand Up @@ -167,7 +178,7 @@ func (c *DenonAVRClient) configureDenon() {
volume = s
}

attributes[entities.VolumeMediaPlayerEntityAttribute] = volume + 80
attributes[string(entities.VolumeMediaPlayerEntityAttribute)] = volume + 80

c.mediaPlayer.SetAttributes(attributes)
})
Expand Down Expand Up @@ -326,14 +337,10 @@ func (c *DenonAVRClient) denonClientLoop() {

// Run Client Loop to handle entity changes from device
for {
select {
case msg := <-c.messages:

switch msg {
case "disconnect":
return
}

msg := <-c.messages
switch msg {
case "disconnect":
return
}
}

Expand Down
34 changes: 17 additions & 17 deletions pkg/client/shellyclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ func (c *ShellyClient) handleNewDeviceDiscovered(device *shelly.ShellyDevice) {

shellySwitch := entities.NewSwitchEntity(device.Id, entities.LanguageText{En: "Shelly " + device.Id}, "")
shellySwitch.AddFeature(entities.OnOffSwitchEntityyFeatures)
shellySwitch.AddFeature(entities.ToggleSwitchEntityCommand)
shellySwitch.AddFeature(entities.ToggleSwitchEntityyFeatures)

shellySwitch.MapCommand(entities.OnSwitchEntityCommand, device.TurnOn)
shellySwitch.MapCommand(entities.OffSwitchEntityCommand, device.TurnOff)
shellySwitch.MapCommand(entities.ToggleLightEntityCommand, device.Toggle)
shellySwitch.MapCommand(entities.ToggleSwitchEntityCommand, device.Toggle)

device.AddMsgReceivedFunc("relay/0", func(msg []byte) {

Expand All @@ -198,17 +198,19 @@ func (c *ShellyClient) handleNewDeviceDiscovered(device *shelly.ShellyDevice) {
shellySwitch.SetAttributes(attributes)
})

c.IntegrationDriver.AddEntity(shellySwitch)
if err := c.IntegrationDriver.AddEntity(shellySwitch); err != nil {
log.WithError(err).Error("Cannot add Entity")
}

}

func (c *ShellyClient) handleRemoveDevice(device *shelly.ShellyDevice) {
log.WithFields(log.Fields{
"ID": device.Id,
"IP Address": device.IPAddress,
"MAC Address": device.MACAddress,
}).Debug("New Shelly Device not available anymore")
}
// func (c *ShellyClient) handleRemoveDevice(device *shelly.ShellyDevice) {
// log.WithFields(log.Fields{
// "ID": device.Id,
// "IP Address": device.IPAddress,
// "MAC Address": device.MACAddress,
// }).Debug("New Shelly Device not available anymore")
// }

// Callen on RT connect
func (c *ShellyClient) shellyClientLoop() {
Expand All @@ -233,15 +235,13 @@ func (c *ShellyClient) shellyClientLoop() {

// Run Client Loop to handle entity changes from device
for {
select {
case msg := <-c.messages:

switch msg {
case "disconnect":
return
}
msg := <-c.messages

switch msg {
case "disconnect":
return
}

}

}
34 changes: 17 additions & 17 deletions pkg/client/tasmotaclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ func (c *TasmotaClient) handleNewDeviceDiscovered(device *tasmota.TasmotaDevice)
// Sonoff Basic
switchEntity := entities.NewSwitchEntity(device.Topic, entities.LanguageText{En: "Tasmota " + device.FriendlyName[0]}, "")
switchEntity.AddFeature(entities.OnOffSwitchEntityyFeatures)
switchEntity.AddFeature(entities.ToggleSwitchEntityCommand)
switchEntity.AddFeature(entities.ToggleSwitchEntityyFeatures)

switchEntity.MapCommand(entities.OnSwitchEntityCommand, device.TurnOn)
switchEntity.MapCommand(entities.OffSwitchEntityCommand, device.TurnOff)
switchEntity.MapCommand(entities.ToggleLightEntityCommand, device.Toggle)
switchEntity.MapCommand(entities.ToggleSwitchEntityCommand, device.Toggle)

device.AddMsgReceivedFunc("RESULT", func(msg []byte) {

Expand Down Expand Up @@ -238,18 +238,20 @@ func (c *TasmotaClient) handleNewDeviceDiscovered(device *tasmota.TasmotaDevice)
}

if tasmotaDevice != nil {
c.IntegrationDriver.AddEntity(tasmotaDevice)
if err := c.IntegrationDriver.AddEntity(tasmotaDevice); err != nil {
log.WithError(err).Error("Cannot add Entity")
}
}

}

func (c *TasmotaClient) handleRemoveDevice(device *tasmota.TasmotaDevice) {
log.WithFields(log.Fields{
"Topic": device.Topic,
"IP Address": device.IPAddress,
"MAC Address": device.MACAddress,
}).Debug("Tasmota Device not available anymore")
}
// func (c *TasmotaClient) handleRemoveDevice(device *tasmota.TasmotaDevice) {
// log.WithFields(log.Fields{
// "Topic": device.Topic,
// "IP Address": device.IPAddress,
// "MAC Address": device.MACAddress,
// }).Debug("Tasmota Device not available anymore")
// }

// Callen on RT connect
func (c *TasmotaClient) tasmotaClientLoop() {
Expand All @@ -274,15 +276,13 @@ func (c *TasmotaClient) tasmotaClientLoop() {

// Run Client Loop to handle entity changes from device
for {
select {
case msg := <-c.messages:

switch msg {
case "disconnect":
return
}
msg := <-c.messages

switch msg {
case "disconnect":
return
}

}

}
4 changes: 3 additions & 1 deletion pkg/cmd/deconz/deconz.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {
}

var config integration.Config
viper.Unmarshal(&config)
if err := viper.Unmarshal(&config); err != nil {
log.WithError(err).Error("Cannot unmarshal config with viper")
}

i, err := integration.NewIntegration(config)
cmd.CheckError(err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/denonavr/denonavr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {
}

var config integration.Config
viper.Unmarshal(&config)
if err := viper.Unmarshal(&config); err != nil {
log.WithError(err).Error("Cannot unmarshal config with viper")
}

i, err := integration.NewIntegration(config)
cmd.CheckError(err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/shelly/shelly.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {
}

var config integration.Config
viper.Unmarshal(&config)
if err := viper.Unmarshal(&config); err != nil {
log.WithError(err).Error("Cannot unmarshal config with viper")
}

i, err := integration.NewIntegration(config)
cmd.CheckError(err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/tasmota/tasmota.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {
}

var config integration.Config
viper.Unmarshal(&config)
if err := viper.Unmarshal(&config); err != nil {
log.WithError(err).Error("Cannot unmarshal config with viper")
}

i, err := integration.NewIntegration(config)
cmd.CheckError(err)
Expand Down
Loading

0 comments on commit f50a0f4

Please sign in to comment.