mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[pihole] Discrepencies between dashboard and channels (#20394)
* Solving some v6 API issues Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
+2
-2
@@ -67,9 +67,9 @@ public class PiHoleActions implements ThingActions {
|
||||
|
||||
@RuleAction(label = "@text/action.disable.label", description = "@text/action.disable.description")
|
||||
public void disableBlocking(
|
||||
@ActionInput(name = "time", label = "@text/action.disable.timeLabel", description = "@text/action.disable.timeDescription") long time)
|
||||
@ActionInput(name = "time", label = "@text/action.disable.timeLabel", description = "@text/action.disable.timeDescription") Number time)
|
||||
throws PiHoleException {
|
||||
disableBlocking(time, null);
|
||||
disableBlocking(time.longValue(), null);
|
||||
}
|
||||
|
||||
public static void disableBlocking(@Nullable ThingActions actions, long time) throws PiHoleException {
|
||||
|
||||
+13
-22
@@ -65,7 +65,6 @@ public class JettyAdminServiceV6 extends AdminService {
|
||||
|
||||
private @Nullable String sid;
|
||||
private @Nullable Instant sessionValidity;
|
||||
private @Nullable Instant midnightUtc;
|
||||
|
||||
public JettyAdminServiceV6(String token, URI baseUrl, HttpClient client, Gson gson) {
|
||||
super(client, gson);
|
||||
@@ -110,18 +109,6 @@ public class JettyAdminServiceV6 extends AdminService {
|
||||
return updateSid();
|
||||
}
|
||||
|
||||
private long getTodayMidnight() {
|
||||
Instant now = Instant.now();
|
||||
Instant local = midnightUtc;
|
||||
|
||||
if (local == null || now.minus(1, ChronoUnit.DAYS).isAfter(local)) {
|
||||
local = now.truncatedTo(ChronoUnit.DAYS);
|
||||
midnightUtc = local;
|
||||
}
|
||||
|
||||
return local.getEpochSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DnsStatistics> summary() throws PiHoleException {
|
||||
logger.debug("Building the as if it was a v5 API");
|
||||
@@ -132,9 +119,12 @@ public class JettyAdminServiceV6 extends AdminService {
|
||||
|
||||
DnsBlockingAnswer blockingAnswer = get(dnsBlockingURI, DnsBlockingAnswer.class);
|
||||
|
||||
long todayMidnight = getTodayMidnight();
|
||||
StatDatabaseSummary statDatabase = get(databaseSummaryURI, StatDatabaseSummary.class, "from",
|
||||
Long.toString(todayMidnight), "until", Long.toString(todayMidnight + 24 * 60 * 60));
|
||||
Instant now = Instant.now();
|
||||
String oneDayAgo = Long.toString(now.minus(24, ChronoUnit.HOURS).getEpochSecond());
|
||||
String toNow = Long.toString(now.getEpochSecond());
|
||||
|
||||
StatDatabaseSummary statDatabase = get(databaseSummaryURI, StatDatabaseSummary.class, "from", oneDayAgo,
|
||||
"until", toNow);
|
||||
|
||||
HistoryClients historyClients = get(historyClientsURI, HistoryClients.class, "N", "0");
|
||||
ConfigAnswer configAnswer = get(configURI, ConfigAnswer.class);
|
||||
@@ -143,12 +133,13 @@ public class JettyAdminServiceV6 extends AdminService {
|
||||
|
||||
DnsStatistics translated = new DnsStatistics(gravity.domainsBeingBlocked(), statDatabase.sumQueries(),
|
||||
statDatabase.sumBlocked(), statDatabase.percentBlocked(), statQueries.uniqueDomains(),
|
||||
statQueries.forwarded(), statQueries.cached(), historyClients.clients().size(), null,
|
||||
statQueries.types().all(), replies.unknown(), replies.nodata(), replies.nxdomain(), replies.cname(),
|
||||
replies.ip(), replies.domain(), replies.rrname(), replies.servfail(), replies.refused(),
|
||||
replies.notimp(), replies.other(), replies.dnssec(), replies.none(), replies.blob(), replies.all(),
|
||||
configAnswer.config().misc().privacylevel(), blockingAnswer.blocking(), new GravityLastUpdated(
|
||||
configAnswer.config().files().gravity() != null, gravity.lastUpdate(), relative));
|
||||
statQueries.forwarded(), statQueries.cached(), historyClients.clients().size(),
|
||||
statAnswer.clients().active(), statQueries.types().all(), replies.unknown(), replies.nodata(),
|
||||
replies.nxdomain(), replies.cname(), replies.ip(), replies.domain(), replies.rrname(),
|
||||
replies.servfail(), replies.refused(), replies.notimp(), replies.other(), replies.dnssec(),
|
||||
replies.none(), replies.blob(), replies.all(), configAnswer.config().misc().privacylevel(),
|
||||
blockingAnswer.blocking(), new GravityLastUpdated(configAnswer.config().files().gravity() != null,
|
||||
gravity.lastUpdate(), relative));
|
||||
|
||||
return Optional.of(translated);
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ import com.google.gson.annotations.SerializedName;
|
||||
* @author Gaël L'hopital - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public record StatAnswer(Queries queries, Clients client, Gravity gravity, double took) {
|
||||
record Clients(int active, int total) {
|
||||
public record StatAnswer(Queries queries, Clients clients, Gravity gravity, double took) {
|
||||
public record Clients(int active, int total) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
<type>binding</type>
|
||||
<name>Pi-hole Binding</name>
|
||||
<description>This is the binding for Pi-hole.</description>
|
||||
<connection>cloud</connection>
|
||||
<connection>local</connection>
|
||||
|
||||
</addon:addon>
|
||||
|
||||
@@ -115,9 +115,11 @@
|
||||
</channel>
|
||||
<channel id="enabled" typeId="enabled-channel"/>
|
||||
<channel id="disable-enable" typeId="disable-enable-channel"/>
|
||||
<channel id="gravity-file-exists" typeId="gravity-file-exists-channel"/>
|
||||
<channel id="gravity-last-update" typeId="gravity-last-update-channel"/>
|
||||
</channels>
|
||||
<properties>
|
||||
<property name="thingTypeVersion">2</property>
|
||||
<property name="thingTypeVersion">3</property>
|
||||
</properties>
|
||||
|
||||
<config-description>
|
||||
|
||||
@@ -20,4 +20,14 @@
|
||||
</update-channel>
|
||||
</instruction-set>
|
||||
</thing-type>
|
||||
<thing-type uid="pihole:server">
|
||||
<instruction-set targetVersion="3">
|
||||
<add-channel id="gravity-file-exists">
|
||||
<type>pihole:gravity-file-exists-channel</type>
|
||||
</add-channel>
|
||||
<add-channel id="gravity-last-update">
|
||||
<type>pihole:gravity-last-update-channel</type>
|
||||
</add-channel>
|
||||
</instruction-set>
|
||||
</thing-type>
|
||||
</update:update-descriptions>
|
||||
|
||||
Reference in New Issue
Block a user