mirror of
https://github.com/He4eT/simple-spaceapi.git
synced 2026-05-04 17:37:24 +00:00
SpaceAPI: inline sensors
This commit is contained in:
parent
a8e56ce3e1
commit
c833fa9c08
1 changed files with 253 additions and 284 deletions
|
|
@ -192,7 +192,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
.map(pickFields(fields))
|
.map(pickFields(fields))
|
||||||
);
|
);
|
||||||
|
|
||||||
const temperatureSensors = await getSensors(
|
const sensors = {
|
||||||
|
temperature: await getSensors(
|
||||||
'api::temperature-sensor.temperature-sensor',
|
'api::temperature-sensor.temperature-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -201,10 +202,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
carbondioxide: await getSensors(
|
||||||
const carbondioxideSensors = await getSensors(
|
|
||||||
'api::carbondioxide-sensor.carbondioxide-sensor',
|
'api::carbondioxide-sensor.carbondioxide-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -213,10 +213,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
door_locked: await getSensors(
|
||||||
const doorLockedSensors = await getSensors(
|
|
||||||
'api::door-locked-sensor.door-locked-sensor',
|
'api::door-locked-sensor.door-locked-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -224,10 +223,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
barometer: await getSensors(
|
||||||
const barometerSensors = await getSensors(
|
|
||||||
'api::barometer-sensor.barometer-sensor',
|
'api::barometer-sensor.barometer-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -236,26 +234,24 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
radiation: await (async () => {
|
||||||
const radiationSensors = await (async () => {
|
|
||||||
const types = [
|
const types = [
|
||||||
'alpha',
|
'alpha',
|
||||||
'beta',
|
'beta',
|
||||||
'gamma',
|
'gamma',
|
||||||
'beta_gamma',
|
'beta_gamma',
|
||||||
]
|
];
|
||||||
|
|
||||||
const sensors = await getSensorsRaw(
|
const sensors = await getSensorsRaw(
|
||||||
'api::radiation-sensor.radiation-sensor',
|
'api::radiation-sensor.radiation-sensor'
|
||||||
)
|
);
|
||||||
|
|
||||||
const draft = Object.fromEntries(types.map((type) => [
|
const draft = Object.fromEntries(types.map((type) => [
|
||||||
type,
|
type,
|
||||||
sensors
|
sensors
|
||||||
.filter((sensor: { type: string }) =>
|
.filter((sensor: { type: string; }) => sensor.type === type)
|
||||||
sensor.type === type)
|
|
||||||
.map(pickFields([
|
.map(pickFields([
|
||||||
'value',
|
'value',
|
||||||
'unit',
|
'unit',
|
||||||
|
|
@ -266,12 +262,11 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
]))
|
]))
|
||||||
]))
|
]));
|
||||||
|
|
||||||
return pickFields(types)(draft)
|
return pickFields(types)(draft);
|
||||||
})()
|
})(),
|
||||||
|
humidity: (await getSensors(
|
||||||
const humiditySensors = (await getSensors(
|
|
||||||
'api::humidity-sensor.humidity-sensor',
|
'api::humidity-sensor.humidity-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -280,16 +275,15 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
)).map((sensor: { unit: string }) => {
|
)).map((sensor: { unit: string; }) => {
|
||||||
const { unit, ...rest } = sensor;
|
const { unit, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
unit: unit === 'percents' ? '%' : unit,
|
unit: unit === 'percents' ? '%' : unit,
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
beverage_supply: await getSensors(
|
||||||
const beverageSupplySensors = await getSensors(
|
|
||||||
'api::beverage-supply.beverage-supply',
|
'api::beverage-supply.beverage-supply',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -298,10 +292,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
power_consumption: await getSensors(
|
||||||
const powerConsumptionSensors = await getSensors(
|
|
||||||
'api::power-consumption-sensor.power-consumption-sensor',
|
'api::power-consumption-sensor.power-consumption-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -310,10 +303,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
power_generation: await getSensors(
|
||||||
const powerGenerationSensors = await getSensors(
|
|
||||||
'api::power-generation-sensor.power-generation-sensor',
|
'api::power-generation-sensor.power-generation-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -322,10 +314,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
wind: (await getSensors(
|
||||||
const windSensors = (await getSensors(
|
|
||||||
'api::wind-sensor.wind-sensor',
|
'api::wind-sensor.wind-sensor',
|
||||||
[
|
[
|
||||||
'properties',
|
'properties',
|
||||||
|
|
@ -339,8 +330,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'properties.gust',
|
'properties.gust',
|
||||||
'properties.direction',
|
'properties.direction',
|
||||||
'properties.elevation',
|
'properties.elevation',
|
||||||
],
|
]
|
||||||
)).map((sensor: { properties: { bits_per_second: number, packets_per_second: number } }) => {
|
)).map((sensor: { properties: { bits_per_second: number; packets_per_second: number; }; }) => {
|
||||||
const { properties, ...rest } = sensor;
|
const { properties, ...rest } = sensor;
|
||||||
|
|
||||||
const propertiesEntries = Object.entries(pickFields([
|
const propertiesEntries = Object.entries(pickFields([
|
||||||
|
|
@ -361,9 +352,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
: { properties: Object.fromEntries(propertiesEntries) }
|
: { properties: Object.fromEntries(propertiesEntries) }
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
network_connections: (await getSensors(
|
||||||
const networkConnectionsSensors = (await getSensors(
|
|
||||||
'api::network-connections-sensor.network-connections-sensor',
|
'api::network-connections-sensor.network-connections-sensor',
|
||||||
[
|
[
|
||||||
'location',
|
'location',
|
||||||
|
|
@ -374,8 +364,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'machines',
|
'machines',
|
||||||
],
|
]
|
||||||
)).map((sensor: { machines: Array<{ name?: string, mac?: string }> }) => {
|
)).map((sensor: { machines: Array<{ name?: string; mac?: string; }>; }) => {
|
||||||
const { machines, ...rest } = sensor;
|
const { machines, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -383,9 +373,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
? {}
|
? {}
|
||||||
: { machines: machines.map(pickFields(['name', 'mac'])) }),
|
: { machines: machines.map(pickFields(['name', 'mac'])) }),
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
account_balance: await getSensors(
|
||||||
const accountBalanceSensors = await getSensors(
|
|
||||||
'api::account-balance-sensor.account-balance-sensor',
|
'api::account-balance-sensor.account-balance-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -394,10 +383,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
total_member_count: await getSensors(
|
||||||
const totalMemberCountSensors = await getSensors(
|
|
||||||
'api::total-member-count-sensor.total-member-count-sensor',
|
'api::total-member-count-sensor.total-member-count-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -405,10 +393,9 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'lastchange',
|
'lastchange',
|
||||||
],
|
]
|
||||||
);
|
),
|
||||||
|
people_now_present: (await getSensors(
|
||||||
const peopleNowPresentSensors = (await getSensors(
|
|
||||||
'api::people-now-present-sensor.people-now-present-sensor',
|
'api::people-now-present-sensor.people-now-present-sensor',
|
||||||
[
|
[
|
||||||
'value',
|
'value',
|
||||||
|
|
@ -420,8 +407,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'names',
|
'names',
|
||||||
],
|
]
|
||||||
)).map((sensor: { names: Array<{ name: string }> }) => {
|
)).map((sensor: { names: Array<{ name: string; }>; }) => {
|
||||||
const { names, ...rest } = sensor;
|
const { names, ...rest } = sensor;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -429,9 +416,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
? {}
|
? {}
|
||||||
: { names: names.map((x) => x.name) }),
|
: { names: names.map((x) => x.name) }),
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
network_traffic: (await getSensors(
|
||||||
const networkTrafficSensors = (await getSensors(
|
|
||||||
'api::network-traffic-sensor.network-traffic-sensor',
|
'api::network-traffic-sensor.network-traffic-sensor',
|
||||||
[
|
[
|
||||||
'properties',
|
'properties',
|
||||||
|
|
@ -445,8 +431,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
[
|
[
|
||||||
'properties.bits_per_second',
|
'properties.bits_per_second',
|
||||||
'properties.packets_per_second',
|
'properties.packets_per_second',
|
||||||
],
|
]
|
||||||
)).map((sensor: { properties: { bits_per_second: number, packets_per_second: number } }) => {
|
)).map((sensor: { properties: { bits_per_second: number; packets_per_second: number; }; }) => {
|
||||||
const { properties, ...rest } = sensor;
|
const { properties, ...rest } = sensor;
|
||||||
|
|
||||||
const propertiesEntries = Object.entries(pickFields([
|
const propertiesEntries = Object.entries(pickFields([
|
||||||
|
|
@ -465,24 +451,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
|
||||||
: { properties: Object.fromEntries(propertiesEntries) }
|
: { properties: Object.fromEntries(propertiesEntries) }
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
|
||||||
const sensors = {
|
|
||||||
temperature: temperatureSensors,
|
|
||||||
carbondioxide: carbondioxideSensors,
|
|
||||||
door_locked: doorLockedSensors,
|
|
||||||
barometer: barometerSensors,
|
|
||||||
radiation: radiationSensors,
|
|
||||||
humidity: humiditySensors,
|
|
||||||
beverage_supply: beverageSupplySensors,
|
|
||||||
power_consumption: powerConsumptionSensors,
|
|
||||||
power_generation: powerGenerationSensors,
|
|
||||||
wind: windSensors,
|
|
||||||
network_connections: networkConnectionsSensors,
|
|
||||||
account_balance: accountBalanceSensors,
|
|
||||||
total_member_count: totalMemberCountSensors,
|
|
||||||
people_now_present: peopleNowPresentSensors,
|
|
||||||
network_traffic: networkTrafficSensors,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Object.entries(sensors).some(([_, sensor]) => !isEmpty(sensor))) {
|
if (Object.entries(sensors).some(([_, sensor]) => !isEmpty(sensor))) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue