Skip to content
Snippets Groups Projects
Commit 23359e27 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Cleanup API

parent b2667ed2
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ func (gw *Gateway) GetZDevice(name string) *Z2MDevice {
func (gw *Gateway) AddZDevice(zDev *Z2MDevice) {
for _, xDev := range zDev.XAALDevices {
dev := xDev.GetXAALDevice()
dev := xDev.getXAALDevice()
slog.Debug("Adding device", "dev", dev.String())
gw.Engine.AddDevice(dev)
}
......@@ -40,7 +40,7 @@ func (gw *Gateway) AddZDevice(zDev *Z2MDevice) {
func (gw *Gateway) RemoveZDevice(zDev *Z2MDevice) {
for _, xDev := range zDev.XAALDevices {
dev := xDev.GetXAALDevice()
dev := xDev.getXAALDevice()
slog.Debug("Removing device", "dev", dev.String())
gw.Engine.RemoveDevice(dev)
}
......
......@@ -118,7 +118,7 @@ func convertMired(value int) int {
return 1e6 / int(value)
}
func convertToFloat64(value interface{}) (float64, error) {
func convertToFloat(value interface{}) (float64, error) {
switch v := value.(type) {
case float32:
return float64(v), nil
......
......@@ -114,7 +114,7 @@ func NewThermometer(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte
}
func (dev *Thermometer) update(payload map[string]interface{}) {
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("temperature").SetValue(value)
}
......@@ -128,7 +128,7 @@ func NewHygrometer(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInter
}
func (dev *Hygrometer) update(payload map[string]interface{}) {
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("humidity").SetValue(value)
}
......@@ -167,7 +167,7 @@ func NewBattery(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterfac
}
func (dev *Battery) update(payload map[string]interface{}) {
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("level").SetValue(value)
}
......@@ -232,12 +232,12 @@ func NewPowerMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInter
func (dev *PowerMeter) update(payload map[string]interface{}) {
// power
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("power").SetValue(value)
}
// energy
value, err = convertToFloat64(payload["energy"])
value, err = convertToFloat(payload["energy"])
if err == nil {
dev.GetAttribute("energy").SetValue(value)
}
......@@ -333,9 +333,9 @@ func (dev *Lamp) update(payload map[string]interface{}) {
if dev.getMode() == "color" {
color, exists := payload["color"].(map[string]interface{})
if exists {
x, _ := convertToFloat64(color["x"])
y, _ := convertToFloat64(color["y"])
brigthness, _ := convertToFloat64(payload["brightness"])
x, _ := convertToFloat(color["x"])
y, _ := convertToFloat(color["y"])
brigthness, _ := convertToFloat(payload["brightness"])
value := xyToColor(x, y, brigthness)
slog.Debug("color", "color", value.Hex(), "x", x, "y", y, "tmp", brigthness)
hue, sat, val := value.Hsv()
......@@ -387,9 +387,9 @@ func (dev *Lamp) setWhiteTemperature(body xaal.MessageBody) *xaal.MessageBody {
func (dev *Lamp) setHSV(body xaal.MessageBody) *xaal.MessageBody {
value, exist := body["hsv"].([]interface{})
if exist {
hue, _ := convertToFloat64(value[0])
sat, _ := convertToFloat64(value[1])
val, _ := convertToFloat64(value[2])
hue, _ := convertToFloat(value[0])
sat, _ := convertToFloat(value[1])
val, _ := convertToFloat(value[2])
color := colorful.Hsv(hue, sat, val)
slog.Debug("setHSV", "color", color.Hex(), "hue", hue, "sat", sat, "val", val)
dev.Z2MDevice.Set(fmt.Sprintf(`{"color": { "hex": "%s" }}`, color.Hex()))
......@@ -494,7 +494,7 @@ func NewVoltMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterf
}
func (dev *VoltMeter) update(payload map[string]interface{}) {
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("voltage").SetValue(value)
}
......@@ -511,7 +511,7 @@ func NewAmpMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterfa
}
func (dev *AmpMeter) update(payload map[string]interface{}) {
value, err := convertToFloat64(payload[dev.Expose.Name])
value, err := convertToFloat(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("current").SetValue(value)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment