Compare commits

..

No commits in common. "main" and "feature/archer-ax50" have entirely different histories.

7 changed files with 18 additions and 43 deletions

View File

@ -13,7 +13,6 @@ type Config struct {
Password string `required:"true" split_words:"true"`
LogFile bool `required:"true" split_words:"true"`
Bin string `required:"true" split_words:"true"`
SubmitDelay int `default:"7500" required:"false" split_words:"true"`
}
func NewConfig(envFilePath string) *Config {

View File

@ -5,7 +5,6 @@ import (
"log"
"time"
"gitea.urkob.com/urko/go-wifi-switcher/pkg/provider"
"github.com/go-rod/rod"
)
@ -30,11 +29,11 @@ func NewArcherAx50(page *rod.Page) ArcherAx50 {
}
func (p ArcherAx50) Login(user, pass string) error {
time.Sleep(time.Millisecond * 5550)
time.Sleep(time.Millisecond * 1250)
p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => {
document.querySelectorAll("input.password-text").forEach((v, i) => {
$("input.password-text").each((i,v) => {
v.click();
v.focus();
v.value="` + pass + `";
@ -42,8 +41,7 @@ func (p ArcherAx50) Login(user, pass string) error {
return '';
}`,
})
time.Sleep(time.Millisecond * 550)
time.Sleep(time.Millisecond * 250)
log.Println(p.passwordID, "DONE")
@ -53,11 +51,12 @@ func (p ArcherAx50) Login(user, pass string) error {
}
login.MustClick()
log.Println(p.loginButtonID, "DONE")
time.Sleep(time.Millisecond * 4550)
time.Sleep(time.Millisecond * 400)
return nil
}
func (p ArcherAx50) SwitchWIFI(cfg provider.SwitchConfig) error {
func (p ArcherAx50) SwitchWIFI() error {
time.Sleep(time.Second * 1)
pageURL := p.page.MustInfo().URL
log.Println("p.page.MustInfo().URL", pageURL)
@ -68,7 +67,7 @@ func (p ArcherAx50) SwitchWIFI(cfg provider.SwitchConfig) error {
wirelessTab.MustClick()
log.Println(p.wirelessTab, "DONE")
time.Sleep(time.Millisecond * 1850)
time.Sleep(time.Millisecond * 750)
checked := p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => {
return document.getElementById('` + p.chkWifi2gID + `').checked;
@ -76,7 +75,6 @@ func (p ArcherAx50) SwitchWIFI(cfg provider.SwitchConfig) error {
})
isChecked := checked.Value.Bool()
log.Println(getCheckedMessage(isChecked))
p.page.MustEvaluate(&rod.EvalOptions{
JS: `() => {
document.getElementById('` + p.chkWifi2gID + `').checked=` + fmt.Sprint(!isChecked) + `;
@ -84,25 +82,14 @@ func (p ArcherAx50) SwitchWIFI(cfg provider.SwitchConfig) error {
}`,
})
time.Sleep(time.Millisecond * 550)
log.Println(p.chkWifi2gID, "DONE")
saveButton, err := p.page.Element(p.saveButtonID)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.saveButtonID, err)
}
saveButton.MustClick()
saveButton.MustClick()
saveButton.MustClick()
log.Println(p.saveButtonID, "DONE")
time.Sleep(time.Millisecond * time.Duration(cfg.SubmitDelay))
time.Sleep(time.Millisecond * 1500)
return nil
}
func getCheckedMessage(isChecked bool) string {
if isChecked {
return "Time to sleep, let's switch off"
}
return "Time to laborate, let's switch WIFI on"
}

View File

@ -5,7 +5,6 @@ import (
"log"
"time"
"gitea.urkob.com/urko/go-wifi-switcher/pkg/provider"
"github.com/go-rod/rod"
)
@ -67,7 +66,7 @@ func (p Huawei) Login(user, pass string) error {
return nil
}
func (p Huawei) SwitchWIFI(cfg provider.SwitchConfig) error {
func (p Huawei) SwitchWIFI() error {
net, err := p.page.Element(p.netID)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.netID, err)

View File

@ -5,7 +5,6 @@ import (
"log"
"time"
"gitea.urkob.com/urko/go-wifi-switcher/pkg/provider"
"github.com/go-rod/rod"
)
@ -63,7 +62,7 @@ func (p Nucom) Login(user, pass string) error {
return nil
}
func (p Nucom) SwitchWIFI(cfg provider.SwitchConfig) error {
func (p Nucom) SwitchWIFI() error {
wirelessMenu, err := p.page.Element(`a[id="` + p.wirelessTabID + `"]`)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wirelessTabID, err)

View File

@ -37,11 +37,7 @@ func (s Switcher) SwitchWIFI(prv provider.ProviderIface) error {
return fmt.Errorf("prv.Login %w", err)
}
switchConfig := provider.SwitchConfig{
SubmitDelay: s.config.SubmitDelay,
}
if err := prv.SwitchWIFI(switchConfig); err != nil {
if err := prv.SwitchWIFI(); err != nil {
return fmt.Errorf("prv.SwitchWIFI %w", err)
}

View File

@ -22,7 +22,6 @@ func main() {
}
config := cfg.NewConfig(envFile)
log.SetFlags(log.Ldate)
log.SetFlags(log.Lmicroseconds)
if config.LogFile {
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))

View File

@ -1,10 +1,6 @@
package provider
type ProviderIface interface {
Login(string, string) error
SwitchWIFI(SwitchConfig) error
}
type SwitchConfig struct {
SubmitDelay int
Login(user, pass string) error
SwitchWIFI() error
}