mirror of
https://github.com/adrianjagielak/home-assistant-futurehome.git
synced 2025-10-04 10:47:10 +00:00
Stop inclusion/exclusion after the first report
This commit is contained in:
parent
351274f56e
commit
000537585d
@ -400,12 +400,150 @@ export function handleExclusionStatusReport(hubId: string, msg: FimpResponse) {
|
||||
);
|
||||
}
|
||||
|
||||
export function handleInclusionReport() {
|
||||
export async function handleInclusionReport(parameters: {
|
||||
hubId: string;
|
||||
demoMode: boolean;
|
||||
hubIp: string;
|
||||
thingsplexUsername: string;
|
||||
thingsplexPassword: string;
|
||||
thingsplexAllowEmpty: boolean;
|
||||
}) {
|
||||
const topicPrefix = `homeassistant/device/futurehome_${parameters.hubId}_hub`;
|
||||
|
||||
pollVinculum('device').catch((e) => log.warn('Failed to request devices', e));
|
||||
pollVinculum('state').catch((e) => log.warn('Failed to request state', e));
|
||||
|
||||
if (parameters.demoMode) {
|
||||
ha?.publish(`${topicPrefix}/inclusion_exclusion_status/state`, 'Done', {
|
||||
retain: true,
|
||||
qos: 2,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!parameters.thingsplexAllowEmpty &&
|
||||
!parameters.thingsplexUsername &&
|
||||
!parameters.thingsplexPassword
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const token = await loginToThingsplex({
|
||||
host: parameters.hubIp,
|
||||
username: parameters.thingsplexUsername,
|
||||
password: parameters.thingsplexPassword,
|
||||
});
|
||||
await connectThingsplexWebSocketAndSend(
|
||||
{
|
||||
host: parameters.hubIp,
|
||||
token: token,
|
||||
},
|
||||
[
|
||||
{
|
||||
address: 'pt:j1/mt:cmd/rt:ad/rn:zigbee/ad:1',
|
||||
service: 'zigbee',
|
||||
cmd: 'cmd.thing.inclusion',
|
||||
val: false,
|
||||
val_t: 'bool',
|
||||
},
|
||||
{
|
||||
address: 'pt:j1/mt:cmd/rt:ad/rn:zw/ad:1',
|
||||
service: 'zwave-ad',
|
||||
cmd: 'cmd.thing.inclusion',
|
||||
val: false,
|
||||
val_t: 'bool',
|
||||
},
|
||||
],
|
||||
);
|
||||
ha?.publish(`${topicPrefix}/inclusion_exclusion_status/state`, 'Done', {
|
||||
retain: true,
|
||||
qos: 2,
|
||||
});
|
||||
} catch (e) {
|
||||
log.error('Failed trying to stop inclusion/exclusion', e);
|
||||
ha?.publish(
|
||||
`${topicPrefix}/inclusion_exclusion_status/state`,
|
||||
'Failed trying to stop inclusion/exclusion.',
|
||||
{
|
||||
retain: true,
|
||||
qos: 2,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function handleExclusionReport() {
|
||||
export async function handleExclusionReport(parameters: {
|
||||
hubId: string;
|
||||
demoMode: boolean;
|
||||
hubIp: string;
|
||||
thingsplexUsername: string;
|
||||
thingsplexPassword: string;
|
||||
thingsplexAllowEmpty: boolean;
|
||||
}) {
|
||||
const topicPrefix = `homeassistant/device/futurehome_${parameters.hubId}_hub`;
|
||||
|
||||
pollVinculum('device').catch((e) => log.warn('Failed to request devices', e));
|
||||
pollVinculum('state').catch((e) => log.warn('Failed to request state', e));
|
||||
|
||||
if (parameters.demoMode) {
|
||||
ha?.publish(`${topicPrefix}/inclusion_exclusion_status/state`, 'Done', {
|
||||
retain: true,
|
||||
qos: 2,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!parameters.thingsplexAllowEmpty &&
|
||||
!parameters.thingsplexUsername &&
|
||||
!parameters.thingsplexPassword
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const token = await loginToThingsplex({
|
||||
host: parameters.hubIp,
|
||||
username: parameters.thingsplexUsername,
|
||||
password: parameters.thingsplexPassword,
|
||||
});
|
||||
await connectThingsplexWebSocketAndSend(
|
||||
{
|
||||
host: parameters.hubIp,
|
||||
token: token,
|
||||
},
|
||||
[
|
||||
{
|
||||
address: 'pt:j1/mt:cmd/rt:ad/rn:zigbee/ad:1',
|
||||
service: 'zigbee',
|
||||
cmd: 'cmd.thing.exclusion',
|
||||
val: false,
|
||||
val_t: 'bool',
|
||||
},
|
||||
{
|
||||
address: 'pt:j1/mt:cmd/rt:ad/rn:zw/ad:1',
|
||||
service: 'zwave-ad',
|
||||
cmd: 'cmd.thing.exclusion',
|
||||
val: false,
|
||||
val_t: 'bool',
|
||||
},
|
||||
],
|
||||
);
|
||||
ha?.publish(`${topicPrefix}/inclusion_exclusion_status/state`, 'Done', {
|
||||
retain: true,
|
||||
qos: 2,
|
||||
});
|
||||
} catch (e) {
|
||||
log.error('Failed trying to stop inclusion/exclusion', e);
|
||||
ha?.publish(
|
||||
`${topicPrefix}/inclusion_exclusion_status/state`,
|
||||
'Failed trying to stop inclusion/exclusion.',
|
||||
{
|
||||
retain: true,
|
||||
qos: 2,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -282,12 +282,26 @@ import { pollVinculum } from './fimp/vinculum';
|
||||
}
|
||||
|
||||
case 'evt.thing.inclusion_report': {
|
||||
handleInclusionReport();
|
||||
handleInclusionReport({
|
||||
hubId,
|
||||
demoMode,
|
||||
hubIp,
|
||||
thingsplexUsername,
|
||||
thingsplexPassword,
|
||||
thingsplexAllowEmpty,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case 'evt.thing.exclusion_report': {
|
||||
handleExclusionReport();
|
||||
handleExclusionReport({
|
||||
hubId,
|
||||
demoMode,
|
||||
hubIp,
|
||||
thingsplexUsername,
|
||||
thingsplexPassword,
|
||||
thingsplexAllowEmpty,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user