Skip to content

Commit

Permalink
Add mDNS scan for HomeAssistant
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Dec 10, 2024
1 parent b125da9 commit 0fc9b58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/bonjour/DiscoveryRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class DiscoveryRecord
{
public:
enum Service { Unknown = 0, HyperHDR, WLED, PhilipsHue, Pico, ESP32_S2, ESP, SerialPort, REFRESH_ALL };
enum Service { Unknown = 0, HyperHDR, WLED, PhilipsHue, HomeAssistant, Pico, ESP32_S2, ESP, SerialPort, REFRESH_ALL };

Service type;
QString hostName;
Expand Down
3 changes: 2 additions & 1 deletion include/bonjour/DiscoveryWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DiscoveryWrapper : public QObject

public slots:
QList<DiscoveryRecord> getPhilipsHUE();
QList<DiscoveryRecord> getHomeAssistant();
QList<DiscoveryRecord> getWLED();
QList<DiscoveryRecord> getHyperHDRServices();
QList<DiscoveryRecord> getAllServices();
Expand All @@ -66,5 +67,5 @@ public slots:
void cleanUp(QList<DiscoveryRecord>& target);

// contains all current active service sessions
QList<DiscoveryRecord> _hyperhdrSessions, _wledDevices, _hueDevices, _espDevices, _picoDevices, _esp32s2Devices;
QList<DiscoveryRecord> _hyperhdrSessions, _wledDevices, _hueDevices, _homeAssistantDevices, _espDevices, _picoDevices, _esp32s2Devices;
};
6 changes: 4 additions & 2 deletions sources/bonjour/BonjourServiceHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ BonjourServiceHelper::BonjourServiceHelper(BonjourServiceRegister* parent, QStri
has_ipv6 = 0;
_scanService = (1 << DiscoveryRecord::Service::HyperHDR) |
(1 << DiscoveryRecord::Service::WLED) |
(1 << DiscoveryRecord::Service::PhilipsHue);
(1 << DiscoveryRecord::Service::PhilipsHue) |
(1 << DiscoveryRecord::Service::HomeAssistant);

_running = true;

Expand Down Expand Up @@ -506,7 +507,8 @@ int BonjourServiceHelper::service_mdns(QString hostname, QString serviceName, in
{
for (auto scanner :{ DiscoveryRecord::Service::HyperHDR,
DiscoveryRecord::Service::WLED,
DiscoveryRecord::Service::PhilipsHue })
DiscoveryRecord::Service::PhilipsHue,
DiscoveryRecord::Service::HomeAssistant })
{
if (_scanService & (1 << scanner))
{
Expand Down
3 changes: 3 additions & 0 deletions sources/bonjour/BonjourServiceRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void BonjourServiceRegister::requestToScanHandler(DiscoveryRecord::Service type)
case (DiscoveryRecord::Service::HyperHDR): _helper->_scanService |= (1 << DiscoveryRecord::Service::HyperHDR); break;
case (DiscoveryRecord::Service::WLED): _helper->_scanService |= (1 << DiscoveryRecord::Service::WLED); break;
case (DiscoveryRecord::Service::PhilipsHue): _helper->_scanService |= (1 << DiscoveryRecord::Service::PhilipsHue); break;
case (DiscoveryRecord::Service::HomeAssistant): _helper->_scanService |= (1 << DiscoveryRecord::Service::HomeAssistant); break;
default: break;
}
}
Expand All @@ -102,6 +103,8 @@ void BonjourServiceRegister::messageFromFriendHandler(bool isExists, QString mdn
type = DiscoveryRecord::Service::WLED;
else if (mdnsString.indexOf(DiscoveryRecord::getmDnsHeader(DiscoveryRecord::Service::PhilipsHue)) >= 0)
type = DiscoveryRecord::Service::PhilipsHue;
else if (mdnsString.indexOf(DiscoveryRecord::getmDnsHeader(DiscoveryRecord::Service::HomeAssistant)) >= 0)
type = DiscoveryRecord::Service::HomeAssistant;
else if (mdnsString.indexOf(DiscoveryRecord::getmDnsHeader(DiscoveryRecord::Service::HyperHDR)) >= 0)
type = DiscoveryRecord::Service::HyperHDR;

Expand Down
2 changes: 2 additions & 0 deletions sources/bonjour/DiscoveryRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const QString DiscoveryRecord::getmDnsHeader(Service service)
switch (service)
{
case(Service::PhilipsHue): return QLatin1String("_hue._tcp"); break;
case(Service::HomeAssistant): return QLatin1String("_home-assistant._tcp"); break;
case(Service::WLED): return QLatin1String("_wled._tcp"); break;
case(Service::HyperHDR): return QLatin1String("_hyperhdr-http._tcp"); break;
default: return "SERVICE_UNKNOWN";
Expand All @@ -49,6 +50,7 @@ const QString DiscoveryRecord::getName(Service _type)
switch (_type)
{
case(Service::PhilipsHue): return "Hue bridge"; break;
case(Service::HomeAssistant): return "Home Assistant"; break;
case(Service::WLED): return "WLED"; break;
case(Service::HyperHDR): return "HyperHDR"; break;
case(Service::Pico): return "Pico/RP2040"; break;
Expand Down
15 changes: 14 additions & 1 deletion sources/bonjour/DiscoveryWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ QList<DiscoveryRecord> DiscoveryWrapper::getPhilipsHUE()
return _hueDevices;
}

QList<DiscoveryRecord> DiscoveryWrapper::getHomeAssistant()
{
cleanUp(_homeAssistantDevices);

emit GlobalSignals::getInstance()->SignalDiscoveryRequestToScan(DiscoveryRecord::Service::HomeAssistant);

return _homeAssistantDevices;
}

QList<DiscoveryRecord> DiscoveryWrapper::getWLED()
{
cleanUp(_wledDevices);
Expand All @@ -104,7 +113,7 @@ QList<DiscoveryRecord> DiscoveryWrapper::getHyperHDRServices()

QList<DiscoveryRecord> DiscoveryWrapper::getAllServices()
{
return _hyperhdrSessions + _esp32s2Devices + _espDevices + _hueDevices + _picoDevices + _wledDevices;
return _hyperhdrSessions + _esp32s2Devices + _espDevices + _hueDevices + _homeAssistantDevices + _picoDevices + _wledDevices;
}

void DiscoveryWrapper::requestServicesScan()
Expand All @@ -113,6 +122,8 @@ void DiscoveryWrapper::requestServicesScan()
emit GlobalSignals::getInstance()->SignalDiscoveryRequestToScan(DiscoveryRecord::Service::WLED);
cleanUp(_hueDevices);
emit GlobalSignals::getInstance()->SignalDiscoveryRequestToScan(DiscoveryRecord::Service::PhilipsHue);
cleanUp(_homeAssistantDevices);
emit GlobalSignals::getInstance()->SignalDiscoveryRequestToScan(DiscoveryRecord::Service::HomeAssistant);
cleanUp(_hyperhdrSessions);
emit GlobalSignals::getInstance()->SignalDiscoveryRequestToScan(DiscoveryRecord::Service::HyperHDR);

Expand Down Expand Up @@ -172,6 +183,8 @@ void DiscoveryWrapper::signalDiscoveryEventHandler(DiscoveryRecord message)
gotMessage(_wledDevices, message);
else if (message.type == DiscoveryRecord::Service::PhilipsHue)
gotMessage(_hueDevices, message);
else if (message.type == DiscoveryRecord::Service::HomeAssistant)
gotMessage(_homeAssistantDevices, message);
else if (message.type == DiscoveryRecord::Service::Pico)
gotMessage(_picoDevices, message);
else if (message.type == DiscoveryRecord::Service::ESP32_S2)
Expand Down

0 comments on commit 0fc9b58

Please sign in to comment.