Skip to content

Commit

Permalink
Fix AIO control states
Browse files Browse the repository at this point in the history
  • Loading branch information
nograx committed Sep 9, 2024
1 parent 10e7018 commit 32e3316
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 91 deletions.
12 changes: 12 additions & 0 deletions src/constants/hubStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export const hubStates: ISolarflowState[] = sharedStates.concat([
role: "value.power",
unit: "W",
},
{
title: "acMode",
nameDe: "AC Modus",
nameEn: "AC mode",
type: "number",
role: "value",
states: {
0: "Nothing",
1: "AC input mode",
2: "AC output mode",
},
},
{
title: "connectedWithAce",
nameDe: "Mit ACE (1500) verbunden",
Expand Down
196 changes: 106 additions & 90 deletions src/helpers/createControlStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ export const createControlStates = async (
}
);

if (type == "solarflow" || type == "hyper" || type == "ace") {
if (
type == "aio" ||
type == "solarflow" ||
type == "hyper" ||
type == "ace"
) {
// State zum Setzen des Output Limit
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.setOutputLimit`,
Expand Down Expand Up @@ -202,101 +207,112 @@ export const createControlStates = async (
);
}

// State zum Setzen des AC Modus
await adapter?.extendObject(`${productKey}.${deviceKey}.control.acMode`, {
type: "state",
common: {
name: {
de: "AC Modus",
en: "AC mode",
},
type: "number",
desc: "acMode",
role: "switch",
min: 0,
max: 2,
step: 1,
read: true,
write: true,
states: {
0: "Nothing",
1: "AC input mode",
2: "AC output mode",
},
},
native: {},
});
if (type == "solarflow" || type == "hyper" || type == "ace") {
// State zum Setzen des Input Limit (AC)
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.setInputLimit`,
{
type: "state",
common: {
name: {
de: "Einzustellende Eingangsleistung",
en: "Control of the input limit",
},
type: "number",
desc: "setInputLimit",
role: "value.power",
read: true,
write: true,
min: 0,
max: type == "ace" ? 900 : 1200,
step: 100,
unit: "W",
},
native: {},
}
);

adapter?.subscribeStates(`${productKey}.${deviceKey}.control.acMode`);
}
adapter?.subscribeStates(
`${productKey}.${deviceKey}.control.setInputLimit`
);

// State zum Setzen des Input Limit (AC)
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.setInputLimit`,
{
type: "state",
common: {
name: {
de: "Einzustellende Eingangsleistung",
en: "Control of the input limit",
},
type: "number",
desc: "setInputLimit",
role: "value.power",
read: true,
write: true,
min: 0,
max: type == "ace" ? 900 : 1200,
step: 100,
unit: "W",
},
native: {},
}
);
// State zum Setzen des AC Schalters
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.acSwitch`,
{
type: "state",
common: {
name: {
de: "AC Schalter",
en: "AC switch",
},
type: "boolean",
desc: "acSwitch",
role: "switch",
read: true,
write: true,
},
native: {},
}
);

adapter?.subscribeStates(
`${productKey}.${deviceKey}.control.setInputLimit`
);
adapter?.subscribeStates(`${productKey}.${deviceKey}.control.acSwitch`);

// State zum Setzen des AC Schalters
await adapter?.extendObject(`${productKey}.${deviceKey}.control.acSwitch`, {
type: "state",
common: {
name: {
de: "AC Schalter",
en: "AC switch",
},
type: "boolean",
desc: "acSwitch",
role: "switch",
read: true,
write: true,
},
native: {},
});
// State zum Setzen des AC Modus
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.acMode`,
{
type: "state",
common: {
name: {
de: "AC Modus",
en: "AC mode",
},
type: "number",
desc: "acMode",
role: "switch",
min: 0,
max: 2,
step: 1,
read: true,
write: true,
states: {
0: "Nothing",
1: "AC input mode",
2: "AC output mode",
},
},
native: {},
}
);

adapter?.subscribeStates(`${productKey}.${deviceKey}.control.acSwitch`);
}
adapter?.subscribeStates(`${productKey}.${deviceKey}.control.acMode`);
}
}

// States only for ACE 1500
if (type == "ace") {
// State zum Setzen des DC Schalters
await adapter?.extendObject(`${productKey}.${deviceKey}.control.dcSwitch`, {
type: "state",
common: {
name: {
de: "DC Schalter",
en: "DC switch",
},
type: "boolean",
desc: "dcSwitch",
role: "switch",
read: true,
write: true,
},
native: {},
});
// States only for ACE 1500
if (type == "ace") {
// State zum Setzen des DC Schalters
await adapter?.extendObject(
`${productKey}.${deviceKey}.control.dcSwitch`,
{
type: "state",
common: {
name: {
de: "DC Schalter",
en: "DC switch",
},
type: "boolean",
desc: "dcSwitch",
role: "switch",
read: true,
write: true,
},
native: {},
}
);

adapter?.subscribeStates(`${productKey}.${deviceKey}.control.dcSwitch`);
adapter?.subscribeStates(`${productKey}.${deviceKey}.control.dcSwitch`);
}
}
};
2 changes: 1 addition & 1 deletion src/services/adapterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const checkVoltage = async (
// Low Voltage Block activated, stop power input immediately
setOutputLimit(adapter, productKey, deviceKey, 0);
}
} else if (voltage >= 48.0) {
} else if (voltage >= 47.5) {
if (adapter.config.useLowVoltageBlock) {
// Deactivate Low Voltage Block
await adapter?.setState(
Expand Down

0 comments on commit 32e3316

Please sign in to comment.