mirror of
https://github.com/Crocmagnon/display-epaper.git
synced 2024-11-23 14:38:02 +01:00
clear display before not refreshing for a while
This commit is contained in:
parent
b7a8a9850a
commit
816d0e53d0
1 changed files with 18 additions and 17 deletions
|
@ -77,19 +77,20 @@ func loop(
|
||||||
weatherClient *weather.Client,
|
weatherClient *weather.Client,
|
||||||
hassClient *home_assistant.Client,
|
hassClient *home_assistant.Client,
|
||||||
) (image.Image, error) {
|
) (image.Image, error) {
|
||||||
if !shouldRun(ctx, hassClient) {
|
var img image.Image = image.White
|
||||||
return currentImg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
img, err := getImg(
|
if shouldDisplay(ctx, hassClient) {
|
||||||
ctx,
|
var err error
|
||||||
time.Now,
|
img, err = getImg(
|
||||||
transportsClient,
|
ctx,
|
||||||
feteClient,
|
time.Now,
|
||||||
weatherClient,
|
transportsClient,
|
||||||
)
|
feteClient,
|
||||||
if err != nil {
|
weatherClient,
|
||||||
return nil, fmt.Errorf("getting black: %w", err)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("getting black: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if imgEqual(currentImg, img, epd.Width, epd.Height) {
|
if imgEqual(currentImg, img, epd.Width, epd.Height) {
|
||||||
|
@ -103,7 +104,7 @@ func loop(
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = initDisplay(display, initFastThreshold)
|
err := initDisplay(display, initFastThreshold)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("initializing display: %w", err)
|
return nil, fmt.Errorf("initializing display: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -116,21 +117,21 @@ func loop(
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldRun(ctx context.Context, hassClient *home_assistant.Client) bool {
|
func shouldDisplay(ctx context.Context, hassClient *home_assistant.Client) bool {
|
||||||
dayNight, err := hassClient.GetState(ctx, "input_select.house_day_night")
|
dayNight, err := hassClient.GetState(ctx, "input_select.house_day_night")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error getting day night: %v ; running\n", err)
|
log.Printf("error getting day night: %v ; displaying anyway\n", err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
presentAway, err := hassClient.GetState(ctx, "input_select.house_present_away")
|
presentAway, err := hassClient.GetState(ctx, "input_select.house_present_away")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error getting day night: %v ; running\n", err)
|
log.Printf("error getting day night: %v ; displaying anyway\n", err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
res := dayNight == "day" && presentAway == "present"
|
res := dayNight == "day" && presentAway == "present"
|
||||||
log.Printf("running: %v\n", res)
|
log.Printf("shouldDisplay: %v\n", res)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue