Home Assistant: configurable charge status values (BC) (#32136)
This commit is contained in:
parent
36a789b5c0
commit
c8b27650ca
6 changed files with 204 additions and 35 deletions
|
|
@ -16,6 +16,7 @@ type HomeAssistant struct {
|
|||
implement.Caps
|
||||
conn *homeassistant.Connection
|
||||
status string
|
||||
states homeassistant.StatusMap
|
||||
enabled string
|
||||
enable string
|
||||
maxcurrent string
|
||||
|
|
@ -30,6 +31,9 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Charger, error) {
|
|||
var cc struct {
|
||||
homeassistant.Config `mapstructure:",squash"`
|
||||
Status string // required - sensor for charge status
|
||||
StatusA string // optional - custom states mapped to status A
|
||||
StatusB string // optional - custom states mapped to status B
|
||||
StatusC string // optional - custom states mapped to status C
|
||||
Enabled string // required - sensor for enabled state
|
||||
Enable string // required - switch/input_boolean for enable/disable
|
||||
MaxCurrent string // required - number entity for setting max current
|
||||
|
|
@ -57,6 +61,11 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Charger, error) {
|
|||
return nil, errors.New("missing maxcurrent number entity")
|
||||
}
|
||||
|
||||
states, err := homeassistant.NewStatusMap(cc.StatusA, cc.StatusB, cc.StatusC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log := util.NewLogger("ha-charger")
|
||||
|
||||
conn, err := cc.Config.NewConnection(log)
|
||||
|
|
@ -68,6 +77,7 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Charger, error) {
|
|||
Caps: implement.New(),
|
||||
conn: conn,
|
||||
status: cc.Status,
|
||||
states: states,
|
||||
enabled: cc.Enabled,
|
||||
enable: cc.Enable,
|
||||
maxcurrent: cc.MaxCurrent,
|
||||
|
|
@ -116,7 +126,7 @@ var _ api.Charger = (*HomeAssistant)(nil)
|
|||
|
||||
// Status implements the api.ChargeState interface
|
||||
func (c *HomeAssistant) Status() (api.ChargeStatus, error) {
|
||||
return c.conn.GetChargeStatus(c.status)
|
||||
return c.conn.GetChargeStatus(c.status, c.states)
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue