From 4d6bf165a7363939e6b4121bdea8052d64fb2100 Mon Sep 17 00:00:00 2001 From: Markus Thierolf <77847348+thierolm@users.noreply.github.com> Date: Fri, 25 Apr 2025 13:05:42 +0200 Subject: [PATCH] Shelly: re-enable PM Mini Gen3 (#20855) --- meter/shelly/gen2.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/meter/shelly/gen2.go b/meter/shelly/gen2.go index 0efee0f64..d5e6dbde8 100644 --- a/meter/shelly/gen2.go +++ b/meter/shelly/gen2.go @@ -109,12 +109,6 @@ func newGen2(helper *request.Helper, uri, model string, channel int, user, passw c.Client.Transport = digest.NewTransport(user, password, c.Client.Transport) } - c.switchstatus = util.ResettableCached(apiCall[Gen2SwitchStatus](c, "Switch.GetStatus"), cache) - c.em1status = util.Cached(apiCall[Gen2EM1Status](c, "EM1.GetStatus"), cache) - c.em1data = util.Cached(apiCall[Gen2EM1Data](c, "EM1Data.GetStatus"), cache) - c.emstatus = util.Cached(apiCall[Gen2EMStatus](c, "EM.GetStatus"), cache) - c.emdata = util.Cached(apiCall[Gen2EMData](c, "EMData.GetStatus"), cache) - var res Gen2Methods if err := c.execCmd("Shelly.ListMethods", false, &res); err != nil { return nil, err @@ -122,6 +116,16 @@ func newGen2(helper *request.Helper, uri, model string, channel int, user, passw c.methods = res.Methods + if c.hasPM1Endpoint() { + c.switchstatus = util.ResettableCached(apiCall[Gen2SwitchStatus](c, "PM1.GetStatus"), cache) + } else { + c.switchstatus = util.ResettableCached(apiCall[Gen2SwitchStatus](c, "Switch.GetStatus"), cache) + } + c.em1status = util.Cached(apiCall[Gen2EM1Status](c, "EM1.GetStatus"), cache) + c.em1data = util.Cached(apiCall[Gen2EM1Data](c, "EM1Data.GetStatus"), cache) + c.emstatus = util.Cached(apiCall[Gen2EMStatus](c, "EM.GetStatus"), cache) + c.emdata = util.Cached(apiCall[Gen2EMData](c, "EMData.GetStatus"), cache) + return c, nil } @@ -264,6 +268,10 @@ func (c *gen2) hasSwitchEndpoint() bool { return c.hasMethod("Switch.GetStatus") } +func (c *gen2) hasPM1Endpoint() bool { + return c.hasMethod("PM1.GetStatus") +} + func (c *gen2) hasEM1Endpoint() bool { return c.hasMethod("EM1.GetStatus") }