Feature: Allow configuration of sunset type
This commit is contained in:
parent
889e191589
commit
e7198073af
@ -66,6 +66,7 @@ struct CONFIG_T {
|
||||
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
||||
double Ntp_Longitude;
|
||||
double Ntp_Latitude;
|
||||
uint8_t Ntp_SunsetType;
|
||||
|
||||
bool Mqtt_Enabled;
|
||||
uint Mqtt_Port;
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#define NTP_TIMEZONEDESCR "Europe/Berlin"
|
||||
#define NTP_LONGITUDE 10.4515f
|
||||
#define NTP_LATITUDE 51.1657f
|
||||
#define NTP_SUNSETTYPE 1
|
||||
|
||||
#define MQTT_ENABLED false
|
||||
#define MQTT_HOST ""
|
||||
|
||||
@ -46,6 +46,7 @@ bool ConfigurationClass::write()
|
||||
ntp["timezone_descr"] = config.Ntp_TimezoneDescr;
|
||||
ntp["latitude"] = config.Ntp_Latitude;
|
||||
ntp["longitude"] = config.Ntp_Longitude;
|
||||
ntp["sunsettype"] = config.Ntp_SunsetType;
|
||||
|
||||
JsonObject mqtt = doc.createNestedObject("mqtt");
|
||||
mqtt["enabled"] = config.Mqtt_Enabled;
|
||||
@ -189,6 +190,7 @@ bool ConfigurationClass::read()
|
||||
strlcpy(config.Ntp_TimezoneDescr, ntp["timezone_descr"] | NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
||||
config.Ntp_Latitude = ntp["latitude"] | NTP_LATITUDE;
|
||||
config.Ntp_Longitude = ntp["longitude"] | NTP_LONGITUDE;
|
||||
config.Ntp_SunsetType = ntp["sunsettype"] | NTP_SUNSETTYPE;
|
||||
|
||||
JsonObject mqtt = doc["mqtt"];
|
||||
config.Mqtt_Enabled = mqtt["enabled"] | MQTT_ENABLED;
|
||||
|
||||
@ -45,8 +45,25 @@ void SunPositionClass::updateSunData()
|
||||
}
|
||||
|
||||
_sun.setCurrentDate(1900 + timeinfo.tm_year, timeinfo.tm_mon + 1, timeinfo.tm_mday);
|
||||
_sunriseMinutes = static_cast<int>(_sun.calcCustomSunrise(SunSet::SUNSET_NAUTICAL));
|
||||
_sunsetMinutes = static_cast<int>(_sun.calcCustomSunset(SunSet::SUNSET_NAUTICAL));
|
||||
|
||||
double sunset_type;
|
||||
switch (config.Ntp_SunsetType) {
|
||||
case 0:
|
||||
sunset_type = SunSet::SUNSET_OFFICIAL;
|
||||
break;
|
||||
case 2:
|
||||
sunset_type = SunSet::SUNSET_CIVIL;
|
||||
break;
|
||||
case 3:
|
||||
sunset_type = SunSet::SUNSET_ASTONOMICAL;
|
||||
break;
|
||||
default:
|
||||
sunset_type = SunSet::SUNSET_NAUTICAL;
|
||||
break;
|
||||
}
|
||||
|
||||
_sunriseMinutes = static_cast<int>(_sun.calcCustomSunrise(sunset_type));
|
||||
_sunsetMinutes = static_cast<int>(_sun.calcCustomSunset(sunset_type));
|
||||
uint minutesPastMidnight = timeinfo.tm_hour * 60 + timeinfo.tm_min;
|
||||
|
||||
_isDayPeriod = (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes);
|
||||
|
||||
@ -81,6 +81,7 @@ void WebApiNtpClass::onNtpAdminGet(AsyncWebServerRequest* request)
|
||||
root["ntp_timezone_descr"] = config.Ntp_TimezoneDescr;
|
||||
root["longitude"] = config.Ntp_Longitude;
|
||||
root["latitude"] = config.Ntp_Latitude;
|
||||
root["sunsettype"] = config.Ntp_SunsetType;
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
@ -125,7 +126,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone") && root.containsKey("longitude") && root.containsKey("latitude"))) {
|
||||
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone") && root.containsKey("longitude") && root.containsKey("latitude") && root.containsKey("sunsettype"))) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||
response->setLength();
|
||||
@ -166,6 +167,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
||||
strlcpy(config.Ntp_TimezoneDescr, root["ntp_timezone_descr"].as<String>().c_str(), sizeof(config.Ntp_TimezoneDescr));
|
||||
config.Ntp_Latitude = root["latitude"].as<double>();
|
||||
config.Ntp_Longitude = root["longitude"].as<double>();
|
||||
config.Ntp_SunsetType = root["sunsettype"].as<uint8_t>();
|
||||
Configuration.write();
|
||||
|
||||
retMsg["type"] = "success";
|
||||
|
||||
@ -243,8 +243,8 @@
|
||||
"Synced": "synchronisiert",
|
||||
"NotSynced": "nicht synchronisiert",
|
||||
"LocalTime": "Lokale Uhrzeit",
|
||||
"Sunrise": "Nautische Morgendämmerung",
|
||||
"Sunset": "Nautische Abenddämmerung",
|
||||
"Sunrise": "Morgendämmerung",
|
||||
"Sunset": "Abenddämmerung",
|
||||
"Mode": "Modus",
|
||||
"Day": "Tag",
|
||||
"Night": "Nacht"
|
||||
@ -359,6 +359,12 @@
|
||||
"LocationConfiguration": "Standortkonfiguration",
|
||||
"Longitude": "Längengrad:",
|
||||
"Latitude": "Breitengrad:",
|
||||
"SunSetType": "Dämmerungstyp:",
|
||||
"SunSetTypeHint": "Beeinflusst die Tag/Nacht Berechnung. Es kann bis zu einer Minute dauern bis der neue Typ angewendet wurde.",
|
||||
"OFFICIAL": "Standard Dämmerung (90.8°)",
|
||||
"NAUTICAL": "Nautische Dämmerung (102°)",
|
||||
"CIVIL": "Bürgerliche Dämmerung (96°)",
|
||||
"ASTONOMICAL": "Astronomische Dämmerung (108°)",
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"ManualTimeSynchronization": "Manuelle Zeitsynchronization",
|
||||
"CurrentOpenDtuTime": "Aktuelle OpenDTU-Zeit:",
|
||||
|
||||
@ -243,8 +243,8 @@
|
||||
"Synced": "synced",
|
||||
"NotSynced": "not synced",
|
||||
"LocalTime": "Local Time",
|
||||
"Sunrise": "Nautical Sunrise",
|
||||
"Sunset": "Nautical Sunset",
|
||||
"Sunrise": "Sunrise",
|
||||
"Sunset": "Sunset",
|
||||
"Mode": "Mode",
|
||||
"Day": "Day",
|
||||
"Night": "Night"
|
||||
@ -359,6 +359,12 @@
|
||||
"LocationConfiguration": "Location Configuration",
|
||||
"Longitude": "Longitude",
|
||||
"Latitude": "Latitude",
|
||||
"SunSetType": "Sunset type",
|
||||
"SunSetTypeHint": "Affects the day/night calculation. It can take up to one minute until the new type will be applied.",
|
||||
"OFFICIAL": "Standard dawn (90.8°)",
|
||||
"NAUTICAL": "Nautical dawn (102°)",
|
||||
"CIVIL": "Civil dawn (96°)",
|
||||
"ASTONOMICAL": "Astronomical dawn (108°)",
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"ManualTimeSynchronization": "Manual Time Synchronization",
|
||||
"CurrentOpenDtuTime": "Current OpenDTU Time:",
|
||||
|
||||
@ -243,8 +243,8 @@
|
||||
"Synced": "synchronisée",
|
||||
"NotSynced": "pas synchronisée",
|
||||
"LocalTime": "Heure locale",
|
||||
"Sunrise": "Nautical Sunrise",
|
||||
"Sunset": "Nautical Sunset",
|
||||
"Sunrise": "Sunrise",
|
||||
"Sunset": "Sunset",
|
||||
"Mode": "Mode",
|
||||
"Day": "Day",
|
||||
"Night": "Night"
|
||||
@ -359,6 +359,12 @@
|
||||
"LocationConfiguration": "Géolocalisation",
|
||||
"Longitude": "Longitude",
|
||||
"Latitude": "Latitude",
|
||||
"SunSetType": "Sunset type",
|
||||
"SunSetTypeHint": "Affects the day/night calculation. It can take up to one minute until the new type will be applied.",
|
||||
"OFFICIAL": "Standard dawn (90.8°)",
|
||||
"NAUTICAL": "Nautical dawn (102°)",
|
||||
"CIVIL": "Civil dawn (96°)",
|
||||
"ASTONOMICAL": "Astronomical dawn (108°)",
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"ManualTimeSynchronization": "Synchronisation manuelle de l'heure",
|
||||
"CurrentOpenDtuTime": "Heure actuelle de l'OpenDTU",
|
||||
|
||||
@ -4,4 +4,5 @@ export interface NtpConfig {
|
||||
ntp_timezone_descr: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
sunsettype: number;
|
||||
}
|
||||
@ -36,6 +36,21 @@
|
||||
<InputElement :label="$t('ntpadmin.Longitude')"
|
||||
v-model="ntpConfigList.longitude"
|
||||
type="number" min="-180" max="180" step="any"/>
|
||||
|
||||
|
||||
<div class="row mb-3">
|
||||
<label class="col-sm-2 col-form-label">
|
||||
{{ $t('ntpadmin.SunSetType') }}
|
||||
<BIconInfoCircle v-tooltip :title="$t('ntpadmin.SunSetTypeHint')" />
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-select" v-model="ntpConfigList.sunsettype">
|
||||
<option v-for="sunsettype in sunsetTypeList" :key="sunsettype.key" :value="sunsettype.key">
|
||||
{{ $t(`ntpadmin.` + sunsettype.value) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</CardElement>
|
||||
<button type="submit" class="btn btn-primary mb-3">{{ $t('ntpadmin.Save') }}</button>
|
||||
</form>
|
||||
@ -67,6 +82,7 @@ import InputElement from '@/components/InputElement.vue';
|
||||
import type { NtpConfig } from "@/types/NtpConfig";
|
||||
import { authHeader, handleResponse } from '@/utils/authentication';
|
||||
import { defineComponent } from 'vue';
|
||||
import { BIconInfoCircle } from 'bootstrap-icons-vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@ -74,6 +90,7 @@ export default defineComponent({
|
||||
BootstrapAlert,
|
||||
CardElement,
|
||||
InputElement,
|
||||
BIconInfoCircle,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -88,6 +105,12 @@ export default defineComponent({
|
||||
alertMessage: "",
|
||||
alertType: "info",
|
||||
showAlert: false,
|
||||
sunsetTypeList: [
|
||||
{ key: 0, value: 'OFFICIAL' },
|
||||
{ key: 1, value: 'NAUTICAL' },
|
||||
{ key: 2, value: 'CIVIL' },
|
||||
{ key: 3, value: 'ASTONOMICAL' },
|
||||
],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user