some code lint
This commit is contained in:
parent
0d83d14329
commit
4c290b0467
@ -26,7 +26,7 @@ type DeviceState struct {
|
|||||||
Setpoint int `json:"setpoint"`
|
Setpoint int `json:"setpoint"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Program_name string `json:"program_name"`
|
Program_name string `json:"program_name"`
|
||||||
Until_time time.Time `json:"until_time"`
|
UntilTime time.Time `json:"until_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DeviceState) Equivalent(state DeviceState) bool {
|
func (s *DeviceState) Equivalent(state DeviceState) bool {
|
||||||
@ -50,7 +50,7 @@ func (s *DeviceState) Equivalent(state DeviceState) bool {
|
|||||||
if state.Setpoint != s.Setpoint {
|
if state.Setpoint != s.Setpoint {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !state.Until_time.Equal(s.Until_time) {
|
if !state.UntilTime.Equal(s.UntilTime) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case "program":
|
case "program":
|
||||||
@ -94,11 +94,10 @@ func (d *Device) Program() (WeekProgram, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) ProgramName() string {
|
func (d *Device) ProgramName() string {
|
||||||
prog_name := "default"
|
|
||||||
if d.State.Program_name != "" {
|
if d.State.Program_name != "" {
|
||||||
prog_name = d.State.Program_name
|
return d.State.Program_name
|
||||||
}
|
}
|
||||||
return prog_name
|
return "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) publishState(pubchan chan Message) error {
|
func (d *Device) publishState(pubchan chan Message) error {
|
||||||
@ -152,11 +151,7 @@ func (d *Device) SetState(log *zerolog.Logger, state DeviceState, pubchan chan M
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.publishState(pubchan); err != nil {
|
return d.publishState(pubchan)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) CheckSetpoint(log *zerolog.Logger, pubchan chan Message) error {
|
func (d *Device) CheckSetpoint(log *zerolog.Logger, pubchan chan Message) error {
|
||||||
@ -166,9 +161,7 @@ func (d *Device) CheckSetpoint(log *zerolog.Logger, pubchan chan Message) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if change {
|
if change {
|
||||||
if err := d.publishState(pubchan); err != nil {
|
return d.publishState(pubchan)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -284,9 +277,9 @@ func (d *Device) handle_always(log *zerolog.Logger, pubchan chan Message) (bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) handle_until_time(log *zerolog.Logger, pubchan chan Message) (bool, error) {
|
func (d *Device) handle_until_time(log *zerolog.Logger, pubchan chan Message) (bool, error) {
|
||||||
*log = log.With().Time("until_time", d.State.Until_time).Logger()
|
*log = log.With().Time("until_time", d.State.UntilTime).Logger()
|
||||||
|
|
||||||
if d.State.Until_time.Before(timeNow()) {
|
if d.State.UntilTime.Before(timeNow()) {
|
||||||
log.Info().Msg("until_time passed, reset")
|
log.Info().Msg("until_time passed, reset")
|
||||||
return d.handle_reset_state(log, pubchan)
|
return d.handle_reset_state(log, pubchan)
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func TestStateEquivalent(t *testing.T) {
|
|||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time,
|
UntilTime: test_time,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
@ -147,7 +147,7 @@ func TestStateEquivalent(t *testing.T) {
|
|||||||
Setpoint: 15,
|
Setpoint: 15,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time,
|
UntilTime: test_time,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@ -162,7 +162,7 @@ func TestStateEquivalent(t *testing.T) {
|
|||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time,
|
UntilTime: test_time,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
@ -177,55 +177,55 @@ func TestStateEquivalent(t *testing.T) {
|
|||||||
Setpoint: 13,
|
Setpoint: 13,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time,
|
UntilTime: test_time,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Until_time: test_time.Add(1 * time.Hour),
|
UntilTime: test_time.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time.Add(1 * time.Hour),
|
UntilTime: test_time.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Until_time: test_time.Add(1 * time.Hour),
|
UntilTime: test_time.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 13,
|
Setpoint: 13,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time.Add(1 * time.Hour),
|
UntilTime: test_time.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Until_time: test_time.Add(1 * time.Hour),
|
UntilTime: test_time.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
DeviceState{
|
DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 14,
|
Setpoint: 14,
|
||||||
Time: test_time,
|
Time: test_time,
|
||||||
Program_name: "other",
|
Program_name: "other",
|
||||||
Until_time: test_time.Add(2 * time.Hour),
|
UntilTime: test_time.Add(2 * time.Hour),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@ -345,20 +345,20 @@ func TestUpdate(t *testing.T) {
|
|||||||
device4.Name = "4"
|
device4.Name = "4"
|
||||||
device4.CurrentSetpoint = 22
|
device4.CurrentSetpoint = 22
|
||||||
device4.State = DeviceState{
|
device4.State = DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 22,
|
Setpoint: 22,
|
||||||
Time: timeNow(),
|
Time: timeNow(),
|
||||||
Until_time: timeNow().Add(2 * time.Hour),
|
UntilTime: timeNow().Add(2 * time.Hour),
|
||||||
}
|
}
|
||||||
|
|
||||||
device5 := test_device
|
device5 := test_device
|
||||||
device5.Name = "5"
|
device5.Name = "5"
|
||||||
device5.CurrentSetpoint = 17
|
device5.CurrentSetpoint = 17
|
||||||
device5.State = DeviceState{
|
device5.State = DeviceState{
|
||||||
Mode: "until_time",
|
Mode: "until_time",
|
||||||
Setpoint: 22,
|
Setpoint: 22,
|
||||||
Time: timeNow().Add(-2 * time.Hour),
|
Time: timeNow().Add(-2 * time.Hour),
|
||||||
Until_time: timeNow().Add(-1 * time.Minute),
|
UntilTime: timeNow().Add(-1 * time.Minute),
|
||||||
}
|
}
|
||||||
|
|
||||||
device6 := test_device
|
device6 := test_device
|
||||||
|
@ -34,13 +34,13 @@ func (d DayOfWeek) DaysBetween(n DayOfWeek) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Monday DayOfWeek = 0
|
Monday DayOfWeek = iota
|
||||||
Thuesday DayOfWeek = 1
|
Thuesday
|
||||||
Wednesday DayOfWeek = 2
|
Wednesday
|
||||||
Thursday DayOfWeek = 3
|
Thursday
|
||||||
Friday DayOfWeek = 4
|
Friday
|
||||||
Saturday DayOfWeek = 5
|
Saturday
|
||||||
Sunday DayOfWeek = 6
|
Sunday
|
||||||
)
|
)
|
||||||
|
|
||||||
func WeekDayEnToFr(weekday time.Weekday) DayOfWeek {
|
func WeekDayEnToFr(weekday time.Weekday) DayOfWeek {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user