Skip to content

Commit

Permalink
[fhome config list --glance]: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Dec 19, 2024
1 parent d1e7d90 commit 037f8fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .run/fhome config list --glance.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="fhome config list --glance" type="GoApplicationRunConfiguration" factoryName="Go Application" focusToolWindowBeforeRun="true">
<module name="fhome" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="config list --glance" />
<kind value="PACKAGE" />
<package value="github.com/bartekpacia/fhome/cmd/fhome" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<pty_enabled value="true" />
<method v="2" />
</configuration>
</component>
8 changes: 6 additions & 2 deletions api/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ const (
ActionGetSystemConfig = "touches"
ActionGetUserConfig = "get_user_config"
ActionEvent = "xevent"
// ActionStatusTouches can be sent to get real values of resources.
ActionStatusTouches = "statustouches"

// ActionStatusTouches returns real values of objects.
ActionStatusTouches = "statustouches"

// ActionStatusTouchesChanged returns mostly the same response as ActionStatusTouches,
// but only for a specific (usually single) changed object.
ActionStatusTouchesChanged = "statustoucheschanged"
)

Expand Down
40 changes: 19 additions & 21 deletions cmd/fhome/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var configCommand = cli.Command{
if err != nil {
return fmt.Errorf("failed to merge configs: %v", err)
}
_ = apiConfig

if cmd.Bool("system") {
w := tabwriter.NewWriter(os.Stdout, 8, 8, 0, ' ', 0)
Expand Down Expand Up @@ -143,39 +144,24 @@ var configCommand = cli.Command{
// To do that, we need to send the "statustouches" action and
// wait for its response.

// Send "statustouches" event.
_, err := client.SendAction(ctx, api.ActionStatusTouches)
msg, err := client.SendAction(ctx, api.ActionStatusTouches)
if err != nil {
return fmt.Errorf("failed to send action: %v", err)
}

msg, err := client.ReadMessage(ctx, api.ActionStatusTouchesChanged, "")
if err != nil {
slog.Error("failed to read message", slog.Any("error", err))
return err
}

var resp api.StatusTouchesChangedResponse
var touchesResponse api.StatusTouchesChangedResponse

err = json.Unmarshal(msg.Raw, &resp)
err = json.Unmarshal(msg.Raw, &touchesResponse)
if err != nil {
slog.Error("failed to unmarshal message", slog.Any("error", err))
return err
}

cellValues := resp.Response.CellValues
for _, cellValue := range cellValues {
err = highlevel.PrintCellData(&cellValue, apiConfig)
if err != nil {
slog.Error("failed to print cell data", slog.Any("error", err))
return err
}
}

cells := make([]struct {
Name string
Value int
}, 0)

mdCells := sysConfig.Response.MobileDisplayProperties.Cells
for _, cell := range mdCells {
if cell.DisplayType != api.Percentage {
Expand All @@ -185,8 +171,20 @@ var configCommand = cli.Command{
continue
}

slog.Info("remapping lighting value", slog.String("cell", cell.Desc), slog.String("step", cell.Step))
val, err := api.RemapLighting(cell.Step)
var cellValue *api.CellValue
for _, cv := range touchesResponse.Response.CellValues {
if cv.ID == cell.ID {
cellValue = &cv
break
}
}
if cellValue == nil {
slog.Error("failed to find corresponding cell value", slog.String("cell", cell.ID))
continue
}

slog.Info("remapping lighting value", slog.String("cell", cell.Desc), slog.String("value", cellValue.Value), slog.String("step", cell.Step))
val, err := api.RemapLighting(cellValue.Value)
if err != nil {
slog.Error(
"error remapping lighting value",
Expand Down

0 comments on commit 037f8fa

Please sign in to comment.