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

Support Konnected GDOs #16

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 18 additions & 1 deletion src/ratgdo-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export class RatgdoAccessory {
private obstructionTimer: NodeJS.Timeout | null;
private readonly platform: RatgdoPlatform;
private readonly status: RatgdoStatus;
private readonly konnectedGDO: boolean;

// The constructor initializes key variables and calls configureDevice().
constructor(platform: RatgdoPlatform, accessory: PlatformAccessory, device: RatgdoDevice) {
constructor(platform: RatgdoPlatform, accessory: PlatformAccessory, device: RatgdoDevice, konnectedGDO: boolean = false) {

this.accessory = accessory;
this.api = platform.api;
Expand All @@ -66,6 +67,7 @@ export class RatgdoAccessory {
this.hints = {} as RatgdoHints;
this.device = device;
this.platform = platform;
this.konnectedGDO = konnectedGDO;

this.log = {

Expand Down Expand Up @@ -1073,6 +1075,11 @@ export class RatgdoAccessory {

endpoint = "cover/door";

if(this.konnectedGDO) {

endpoint = "cover/garage_door";
}

switch(payload) {

case "closed":
Expand Down Expand Up @@ -1113,13 +1120,23 @@ export class RatgdoAccessory {
case "light":

endpoint = "light/light";

if(this.konnectedGDO) {

endpoint = "light/garage_light";
}
action = (payload === "on") ? "turn_on" : "turn_off";

break;

case "lock":

endpoint = "lock/lock_remotes";

if(this.konnectedGDO) {

endpoint = "lock/lock";
}
action = (payload === "lock") ? "lock" : "unlock";

break;
Expand Down
35 changes: 24 additions & 11 deletions src/ratgdo-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {
// Make sure we cleanup our mDNS client on shutdown.
this.api.on(APIEvent.SHUTDOWN, () => mdns.destroy());

// Start ESPHome device discovery.
const mdnsBrowser = mdns.find({type: "esphomelib"}, this.discoverRatgdoDevice.bind(this));
// Define supported mDNS types
const mdnsTypes = ['esphomelib', 'konnected'];

// Trigger an initial update of our discovery.
mdnsBrowser.update();
// For each supported type
for(const mdnsType of mdnsTypes){
// Start ESPHome device discovery.
const mdnsBrowser = mdns.find({type: mdnsType}, this.discoverRatgdoDevice.bind(this));

// Refresh device discovery regular intervals.
setInterval(() => mdnsBrowser.update(), RATGDO_AUTODISCOVERY_INTERVAL * 1000);
// Trigger an initial update of our discovery.
mdnsBrowser.update();

// Refresh device discovery regular intervals.
setInterval(() => mdnsBrowser.update(), RATGDO_AUTODISCOVERY_INTERVAL * 1000);
}
}

// Ratgdo ESPHome device discovery.
Expand All @@ -118,9 +124,13 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {
value?: string
}

// We're only interested in Ratgdo devices with valid IP addresses. Otherwise, we're done.
if(((service.txt as Record<string, string>).project_name !== "ratgdo.esphome") || !service.addresses) {
// Support Konnected's variant on ratgdo
const konnectedGDO = (service.txt as Record<string, string>).project_name.includes('konnected.garage-door');

// We're only interested in Ratgdo devices with valid IP addresses. Otherwise, we're done.
if(!(
(service.txt as Record<string, string>).project_name === "ratgdo.esphome" || konnectedGDO
) || !service.addresses) {
return;
}

Expand All @@ -131,7 +141,7 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {
const mac = (service.txt as Record<string, string>).mac.toUpperCase().replace(/(.{2})(?=.)/g, "$1:");

// Configure the device.
const ratgdoAccessory = this.configureGdo(address, mac, (service.txt as Record<string, string>).friendly_name, (service.txt as Record<string, string>).version);
const ratgdoAccessory = this.configureGdo(address, mac, (service.txt as Record<string, string>).friendly_name, (service.txt as Record<string, string>).version, konnectedGDO);

// If we've already configured this one, we're done.
if(!ratgdoAccessory) {
Expand Down Expand Up @@ -234,6 +244,7 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {

break;

case "cover-garage_door":
case "cover-door":

switch(event.current_operation) {
Expand Down Expand Up @@ -264,13 +275,15 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {

break;

case "light-garage_light":
case "light-light":

ratgdoAccessory.updateState("light", event.state === "OFF" ? "off" : "on");

break;

case "lock-lock_remotes":
case "lock-lock":

ratgdoAccessory.updateState("lock", event.state === "LOCKED" ? "locked" : "unlocked");

Expand Down Expand Up @@ -312,7 +325,7 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {
}

// Configure a discovered garage door opener.
private configureGdo(address: string, mac: string, name: string, firmwareVersion: string): RatgdoAccessory | null {
private configureGdo(address: string, mac: string, name: string, firmwareVersion: string, konnectedGDO = false): RatgdoAccessory | null {

// If we've already discovered this device, we're done.
if(this.discoveredDevices[mac]) {
Expand Down Expand Up @@ -380,7 +393,7 @@ export class RatgdoPlatform implements DynamicPlatformPlugin {
this.log.info("Configuring: %s (address: %s mac: %s ESPHome firmware: v%s).", device.name, device.address, device.mac, device.firmwareVersion);

// Add it to our list of configured devices.
this.configuredDevices[uuid] = new RatgdoAccessory(this, accessory, device);
this.configuredDevices[uuid] = new RatgdoAccessory(this, accessory, device, konnectedGDO);

// Refresh the accessory cache.
this.api.updatePlatformAccessories([accessory]);
Expand Down