diff --git a/gateway/include/devices.h b/gateway/include/devices.h index ac68c03..ef1ed16 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -15,47 +15,45 @@ unordered_map p1Switches; auto gatewayDevice = &DeviceConfig::create(MAIN_DEVICE_ID).withName("RC Gateway").withManufacturer("Adafruit").withModel("Huzzah Esp8266"); -namespace OilTank { - Sensor* buildRoomSensor(const char* id) { - DeviceConfig* device = &DeviceConfig::create(id) - .withName("Servers room") - .withManufacturer("Atmel") - .withModel("AtTiny85") - .withArea("Basement") - .withParent(gatewayDevice); - return Builder::instance(id) - .asDevice(device) - .withValueTemplate("{{ value_json.sensor.temperature }}") - .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.5)|round(2)*100/2)|int }}"}) - .build(); - } +Sensor* buildRoomSensor(const char* id) { + DeviceConfig* device = &DeviceConfig::create(id) + .withName("Servers room") + .withManufacturer("Atmel") + .withModel("AtTiny85") + .withArea("Basement") + .withParent(gatewayDevice); + return Builder::instance(id) + .asDevice(device) + .withValueTemplate("{{ value_json.sensor.temperature }}") + .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) + .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.5)|round(2)*100/2)|int }}"}) + .build(); +} - Sensor* buildTankSensor(const char* id) { - DeviceConfig* device = &DeviceConfig::create(id) - .withName("Oil tank") - .withManufacturer("Arduino") - .withModel("Pro Mini") - .withArea("Basement") - .withParent(gatewayDevice); - return Builder::instance(new Sensor{ "Level", id }) - .asDevice(device) - .withUnitMeasure("%") +Sensor* buildTankSensor(const char* id) { + DeviceConfig* device = &DeviceConfig::create(id) + .withName("Oil tank") + .withManufacturer("Arduino") + .withModel("Pro Mini") + .withArea("Basement") + .withParent(gatewayDevice); + return Builder::instance(new Sensor{ "Level", id }) + .asDevice(device) + .withUnitMeasure("%") + .withSensorStateClass(MEASUREMENT) + .withIcon("mdi:hydraulic-oil-level") + .withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}") + .addSecondary( + Builder::instance(new Sensor{ "Depth", id }) + .withDeviceClass("distance") + .withUnitMeasure("cm") .withSensorStateClass(MEASUREMENT) - .withIcon("mdi:hydraulic-oil-level") - .withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}") - .addSecondary( - Builder::instance(new Sensor{ "Depth", id }) - .withDeviceClass("distance") - .withUnitMeasure("cm") - .withSensorStateClass(MEASUREMENT) - .withValueTemplate("{{ value_json.sensor.value }}") - .build() - ) - .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-4.8)|round(2)*100/1.6)|int }}"}) - .build(); - } + .withValueTemplate("{{ value_json.sensor.value }}") + .build() + ) + .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) + .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-4.8)|round(2)*100/1.6)|int }}"}) + .build(); } struct PollinSwitch : Switch { @@ -146,6 +144,6 @@ Command* commands[] = { }; Sensor* sensors[] = { - OilTank::buildRoomSensor("4"), - OilTank::buildTankSensor("7") + buildRoomSensor("4"), + buildTankSensor("7") };