Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix On/Off Light implementation #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Here is an overview of the devices (light types) Espalexa can emulate:
| EspalexaDeviceType::whitespectrum | Color temperature adjustment not working on Dot |
| EspalexaDeviceType::color | Works as intended (dimming + color) |
| EspalexaDeviceType::extendedcolor | Color temperature adjustment not working on Dot |
| EspalexaDeviceType::onoff (experimental) | Deprecated. Treated as dimmable. |
| EspalexaDeviceType::onoff | Works as intended |

See the example `EspalexaFullyFeatured` to learn how to define each device type and use the new EspalexaDevice pointer callback function type!

Expand Down
37 changes: 27 additions & 10 deletions src/Espalexa.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ class Espalexa {
{
switch (t)
{
case EspalexaDeviceType::dimmable: return "Dimmable light";
case EspalexaDeviceType::whitespectrum: return "Color temperature light";
case EspalexaDeviceType::color: return "Color light";
case EspalexaDeviceType::extendedcolor: return "Extended color light";
case EspalexaDeviceType::dimmable: return PSTR("Dimmable light");
case EspalexaDeviceType::whitespectrum: return PSTR("Color temperature light");
case EspalexaDeviceType::color: return PSTR("Color light");
case EspalexaDeviceType::extendedcolor: return PSTR("Extended color light");
case EspalexaDeviceType::onoff: return PSTR("On/off light");
default: return "";
}
}
Expand All @@ -113,6 +114,7 @@ class Espalexa {
case EspalexaDeviceType::whitespectrum: return "LWT010";
case EspalexaDeviceType::color: return "LST001";
case EspalexaDeviceType::extendedcolor: return "LCT015";
case EspalexaDeviceType::onoff: return "HASS321";
default: return "";
}
}
Expand Down Expand Up @@ -159,12 +161,27 @@ class Espalexa {
if (static_cast<uint8_t>(dev->getType()) > 1)
sprintf(buf_cm,PSTR("\",\"colormode\":\"%s"), modeString(dev->getColorMode()));

sprintf_P(buf, PSTR("{\"state\":{\"on\":%s,\"bri\":%u%s%s,\"alert\":\"none%s\",\"mode\":\"homeautomation\",\"reachable\":true},"
"\"type\":\"%s\",\"name\":\"%s\",\"modelid\":\"%s\",\"manufacturername\":\"Philips\",\"productname\":\"E%u"
"\",\"uniqueid\":\"%s\",\"swversion\":\"espalexa-2.7.0\"}")

, (dev->getValue())?"true":"false", dev->getLastValue()-1, buf_col, buf_ct, buf_cm, typeString(dev->getType()),
dev->getName().c_str(), modelidString(dev->getType()), static_cast<uint8_t>(dev->getType()), buf_lightid);

if (static_cast<uint8_t>(dev->getType()) == 0)
{
// On/Off
sprintf_P(buf, PSTR("{\"state\":{\"on\":%s,\"alert\":\"none%\",\"reachable\":true},"
"\"type\":\"%s\",\"name\":\"%s\",\"modelid\":\"%s\",\"manufacturername\":\"Philips\",\"uniqueid\":\"%s\",\"swversion\":\"espalexa-2.7.0\"}")

, (dev->getValue())?"true":"false", typeString(dev->getType()),
dev->getName().c_str(), modelidString(dev->getType()), buf_lightid);
Serial.println(buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Serial.println() seems to be a debug leftover.

Note: I would love to see this PR merged. I tested the changes myself and they worked nice, thanks for doing this!

}
else
{

sprintf_P(buf, PSTR("{\"state\":{\"on\":%s,\"bri\":%u%s%s,\"alert\":\"none%s\",\"mode\":\"homeautomation\",\"reachable\":true},"
"\"type\":\"%s\",\"name\":\"%s\",\"modelid\":\"%s\",\"manufacturername\":\"Philips\",\"productname\":\"E%u"
"\",\"uniqueid\":\"%s\",\"swversion\":\"espalexa-2.7.0\"}")

, (dev->getValue())?"true":"false", dev->getLastValue()-1, buf_col, buf_ct, buf_cm, typeString(dev->getType()),
dev->getName().c_str(), modelidString(dev->getType()), static_cast<uint8_t>(dev->getType()), buf_lightid);
}
}

//Espalexa status page /espalexa
Expand Down
1 change: 0 additions & 1 deletion src/EspalexaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ EspalexaDevice::EspalexaDevice(String deviceName, DeviceCallbackFunction gnCallb
_deviceName = deviceName;
_callbackDev = gnCallback;
_type = t;
if (t == EspalexaDeviceType::onoff) _type = EspalexaDeviceType::dimmable; //on/off is broken, so make dimmable device instead
if (t == EspalexaDeviceType::whitespectrum) _mode = EspalexaColorMode::ct;
_val = initialValue;
_val_last = _val;
Expand Down