Skip to content

Commit

Permalink
Fix code after some testings (home-assistant#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli authored Sep 22, 2022
1 parent c02fd14 commit cedd66e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ go build -ldflags "-X main.version="

```shell
gdbus introspect --system --dest io.hass.os --object-path /io/hass/os
gdbus call --system --dest io.hass.os --object-path /io/hass/os/Boards/Yellow --method org.freedesktop.DBus.Properties.Set io.hass.os.Boards.Yellow PowerLED "<false>"
```
8 changes: 3 additions & 5 deletions boards/yellow/yellow.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func setStatusLEDPower(c *prop.Change) *dbus.Error {
optLEDPower = c.Value.(bool)

var err error
if optLEDPower {
if c.Value.(bool) {
err = bootFile.DisableOption("dtparam=pwr_led_trigger")
} else {
err = bootFile.SetOption("dtparam=pwr_led_trigger", "none")
Expand All @@ -61,11 +61,10 @@ func setStatusLEDPower(c *prop.Change) *dbus.Error {

func setStatusLEDDisk(c *prop.Change) *dbus.Error {
logging.Info.Printf("Set Yellow Disk LED to %t", c.Value)
// FIXME: set new LED state out of sysfs
optLEDDisk = c.Value.(bool)

var err error
if optLEDPower {
if c.Value.(bool) {
err = bootFile.DisableOption("dtparam=act_led_trigger")
} else {
err = bootFile.SetOption("dtparam=act_led_trigger", "none")
Expand All @@ -79,11 +78,10 @@ func setStatusLEDDisk(c *prop.Change) *dbus.Error {

func setStatusLEDHeartbeat(c *prop.Change) *dbus.Error {
logging.Info.Printf("Set Yellow Heartbeat LED to %t", c.Value)
// FIXME: set new LED state out of sysfs
optLEDHeartbeat = c.Value.(bool)

var err error
if optLEDPower {
if c.Value.(bool) {
err = bootFile.DisableOption("dtparam=usr_led_trigger")
} else {
err = bootFile.SetOption("dtparam=usr_led_trigger", "none")
Expand Down
6 changes: 5 additions & 1 deletion utils/bootfile/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ func (e Editor) SetOption(optionName string, value string) error {

func (e Editor) writeNewBootFile(lines []string) error {
// Write all lines back to boot config file
reader := strings.NewReader(strings.Join(lines, "\n"))
raw := strings.Join(lines, "\n")
if !strings.HasSuffix(raw, "\n") {
raw += "\n"
}
reader := strings.NewReader(raw)

err := atomic.WriteFile(e.FilePath, reader)
if err != nil {
Expand Down

0 comments on commit cedd66e

Please sign in to comment.