Skip to content

Commit

Permalink
print poe status after power cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Dec 23, 2024
1 parent 1fa13b4 commit 3725ed6
Show file tree
Hide file tree
Showing 5 changed files with 643 additions and 1,087 deletions.
17 changes: 10 additions & 7 deletions poe_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"slices"
"strings"
)

Expand Down Expand Up @@ -96,13 +97,15 @@ func (poe *PoeCyclePowerCommand) cyclePowerGs316EPx(args *GlobalOptions) error {
return errors.New(result)
}

// TODO print POE configuration
//settings, err := requestPoeConfiguration(args, poe.Address, poeExt)
//if err != nil {
// return err
//}
//changedPorts := collectChangedPoePortConfiguration(poe.Ports, settings)
//prettyPrintSettings(args.OutputFormat, changedPorts)
// hint in contrast to GS30x, we print PO status here, as this seems more useful
statuses, err := getPoeStatus(args, poe.Address)
if err != nil {
return err
}
statuses = filter(statuses, func(status PoePortStatus) bool {
return slices.Contains(poe.Ports, int(status.PortIndex))
})
prettyPrintStatus(args.OutputFormat, statuses)
return nil
}

Expand Down
23 changes: 16 additions & 7 deletions poe_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,29 @@ type PoeStatusCommand struct {
}

func (poe *PoeStatusCommand) Run(args *GlobalOptions) error {
statusPage, err := requestPoePortStatusPage(args, poe.Address)
statuses, err := getPoeStatus(args, poe.Address)
if err != nil {
return err
}
prettyPrintStatus(args.OutputFormat, statuses)
return nil

}

func getPoeStatus(args *GlobalOptions, address string) ([]PoePortStatus, error) {
var result []PoePortStatus
statusPage, err := requestPoePortStatusPage(args, address)
if err != nil {
return result, err
}
if checkIsLoginRequired(statusPage) {
return errors.New("no content. please, (re-)login first")
return result, errors.New("no content. please, (re-)login first")
}
var statuses []PoePortStatus
statuses, err = findPortStatusInHtml(args.model, strings.NewReader(statusPage))
result, err = findPortStatusInHtml(args.model, strings.NewReader(statusPage))
if err != nil {
return err
return result, err
}
prettyPrintStatus(args.OutputFormat, statuses)
return nil
return result, nil
}

func prettyPrintStatus(format OutputFormat, statuses []PoePortStatus) {
Expand Down
10 changes: 5 additions & 5 deletions poe_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func TestFindPortStatusInHtml(t *testing.T) {
model: "GS316EP",
fileName: "poePortStatus_GetData_true.html",
expectedNumberOfStatuses: 15,
expectedPoePowerClass: "3",
expectedPoePowerClass: "2",
expectedPoePortStatus: "Delivering Power",
expectedVoltageInVolt: 53,
expectedCurrentInMilliAmps: 61,
expectedPowerInWatt: 3.2,
expectedTemperatureInCelsius: 22,
expectedVoltageInVolt: 54,
expectedCurrentInMilliAmps: 22,
expectedPowerInWatt: 1.1,
expectedTemperatureInCelsius: 23,
expectedErrorStatus: "No Error",
expectedPortName: "AGER 31 SUR Tech",
},
Expand Down
Loading

0 comments on commit 3725ed6

Please sign in to comment.