diff --git a/bundles/org.openhab.binding.pihole/README.md b/bundles/org.openhab.binding.pihole/README.md index 51585fe6cf..e7b29feaa5 100644 --- a/bundles/org.openhab.binding.pihole/README.md +++ b/bundles/org.openhab.binding.pihole/README.md @@ -11,6 +11,7 @@ The Pi-hole Binding allows you to monitor Pi-hole statistics and control its fun - Real-time Statistics: Monitor key metrics such as the number of domains being blocked, DNS queries made today, ads blocked today, and more. - Control: Enable or disable Pi-hole's blocking functionality, configure blocking options, and adjust privacy settings directly from openHAB. - Integration: Seamlessly integrate Pi-hole data and controls with other openHAB items and rules to create advanced automation scenarios. +- Version 6 of piHole is supported (configured via the `serverVersion` configuration parameter) starting with version 6.3 (6.2 will not work). ## Supported Things @@ -29,38 +30,38 @@ The Pi-hole Binding allows you to monitor Pi-hole statistics and control its fun ## Channels -| Channel | Type | Read/Write | Description | -|-------------------------|----------|------------|------------------------------------------------------------| -| domains-being-blocked | Number | RO | The total number of domains currently being blocked. | -| dns-queries-today | Number | RO | The count of DNS queries made today. | -| ads-blocked-today | Number | RO | The number of ads blocked today. | -| ads-percentage-today | Number | RO | The percentage of ads blocked today. | -| unique-domains | Number | RO | The count of unique domains queried. | -| queries-forwarded | Number | RO | The number of queries forwarded to an external DNS server. | -| queries-cached | Number | RO | The number of queries served from the cache. | -| clients-ever-seen | Number | RO | The total number of unique clients ever seen. | -| unique-clients | Number | RO | The current count of unique clients. | -| dns-queries-all-types | Number | RO | The total number of DNS queries of all types. | -| reply-unknown | Number | RO | DNS replies with an unknown status. | -| reply-nodata | Number | RO | DNS replies indicating no data. | -| reply-nxdomain | Number | RO | DNS replies indicating non-existent domain. | -| reply-cname | Number | RO | DNS replies with a CNAME record. | -| reply-ip | Number | RO | DNS replies with an IP address. | -| reply-domain | Number | RO | DNS replies with a domain name. | -| reply-rrname | Number | RO | DNS replies with a resource record name. | -| reply-servfail | Number | RO | DNS replies indicating a server failure. | -| reply-refused | Number | RO | DNS replies indicating refusal. | -| reply-notimp | Number | RO | DNS replies indicating not implemented. | -| reply-other | Number | RO | DNS replies with other statuses. | -| reply-dnssec | Number | RO | DNS replies with DNSSEC information. | -| reply-none | Number | RO | DNS replies with no data. | -| reply-blob | Number | RO | DNS replies with a BLOB (binary large object). | -| dns-queries-all-replies | Number | RO | The total number of DNS queries with all reply types. | -| privacy-level | Number | RO | The privacy level setting. | -| enabled | Switch | RO | The current status of blocking | -| disable-enable | String | RW | Is blocking enabled/disabled | -| gravity-last-update | DateTime | RO | Last update of gravity | -| gravity-file-exists | DateTime | RO | Does gravity file exists | +| Channel | Type | Read/Write | Description | +|-------------------------|----------------------|------------|------------------------------------------------------------| +| domains-being-blocked | Number | RO | The total number of domains currently being blocked. | +| dns-queries-today | Number | RO | The count of DNS queries made today. | +| ads-blocked-today | Number | RO | The number of ads blocked today. | +| ads-percentage-today | Number:Dimensionless | RO | The percentage of ads blocked today. | +| unique-domains | Number | RO | The count of unique domains queried. | +| queries-forwarded | Number | RO | The number of queries forwarded to an external DNS server. | +| queries-cached | Number | RO | The number of queries served from the cache. | +| clients-ever-seen | Number | RO | The total number of unique clients ever seen. | +| unique-clients | Number | RO | The current count of unique clients. | +| dns-queries-all-types | Number | RO | The total number of DNS queries of all types. | +| reply-unknown | Number | RO | DNS replies with an unknown status. | +| reply-nodata | Number | RO | DNS replies indicating no data. | +| reply-nxdomain | Number | RO | DNS replies indicating non-existent domain. | +| reply-cname | Number | RO | DNS replies with a CNAME record. | +| reply-ip | Number | RO | DNS replies with an IP address. | +| reply-domain | Number | RO | DNS replies with a domain name. | +| reply-rrname | Number | RO | DNS replies with a resource record name. | +| reply-servfail | Number | RO | DNS replies indicating a server failure. | +| reply-refused | Number | RO | DNS replies indicating refusal. | +| reply-notimp | Number | RO | DNS replies indicating not implemented. | +| reply-other | Number | RO | DNS replies with other statuses. | +| reply-dnssec | Number | RO | DNS replies with DNSSEC information. | +| reply-none | Number | RO | DNS replies with no data. | +| reply-blob | Number | RO | DNS replies with a BLOB (binary large object). | +| dns-queries-all-replies | Number | RO | The total number of DNS queries with all reply types. | +| privacy-level | Number | RO | The privacy level setting. | +| enabled | Switch | RO | The current status of blocking | +| disable-enable | String | RW | Is blocking enabled/disabled | +| gravity-last-update | DateTime | RO | Last update of gravity | +| gravity-file-exists | DateTime | RO | Does gravity file exists | ## Full Example @@ -77,7 +78,7 @@ Thing pihole:server:a4a077edb8 "Pi-hole" @ "Location" Type number : domains_being_blocked "Domains Blocked" [ ] Type number : dns_queries_today "DNS Queries Today" [ ] Type number : ads_blocked_today "Ads Blocked Today" [ ] - Type number : ads_percentage_today "Ads Percentage Today" [ ] + Type Number:Dimensionless : ads_percentage_today "Ads Percentage Today" [ ] Type number : unique_domains "Unique Domains" [ ] Type number : queries_forwarded "Queries Forwarded" [ ] Type number : queries_cached "Queries Cached" [ ] @@ -111,7 +112,7 @@ Thing pihole:server:a4a077edb8 "Pi-hole" @ "Location" Number domains_being_blocked "Domains Blocked" { channel="pihole:server:a4a077edb8:domains_being_blocked" } Number dns_queries_today "DNS Queries Today" { channel="pihole:server:a4a077edb8:dns_queries_today" } Number ads_blocked_today "Ads Blocked Today" { channel="pihole:server:a4a077edb8:ads_blocked_today" } -Number ads_percentage_today "Ads Percentage Today" { channel="pihole:server:a4a077edb8:ads_percentage_today" } +Number:Dimensionless ads_percentage_today "Ads Percentage Today" { channel="pihole:server:a4a077edb8:ads_percentage_today" } Number unique_domains "Unique Domains" { channel="pihole:server:a4a077edb8:unique_domains" } Number queries_forwarded "Queries Forwarded" { channel="pihole:server:a4a077edb8:queries_forwarded" } Number queries_cached "Queries Cached" { channel="pihole:server:a4a077edb8:queries_cached" } diff --git a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/JettyAdminServiceV6.java b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/JettyAdminServiceV6.java index 668e29b45e..5a6097dd56 100644 --- a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/JettyAdminServiceV6.java +++ b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/JettyAdminServiceV6.java @@ -87,9 +87,13 @@ public class JettyAdminServiceV6 extends AdminService { var request = client.newRequest(authURI).timeout(TIMEOUT_SECONDS, SECONDS).method(HttpMethod.POST) .header(HttpHeader.ACCEPT, "application/json").content(new StringContentProvider(tokenJson)); var content = send(request).getContentAsString(); + logger.debug("Session update request answer: {}", content); if (gson.fromJson(content, SessionAnswer.class) instanceof SessionAnswer answer) { Session session = answer.session(); + if (session == null) { + throw new PiHoleException("Received an empty session"); + } sid = session.sid(); sessionValidity = Instant.now().plusSeconds(session.cautiousValidity()); return session.sid(); diff --git a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/Blocking.java b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/Blocking.java index 394c528f5a..09a029281d 100644 --- a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/Blocking.java +++ b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/Blocking.java @@ -20,5 +20,5 @@ import org.eclipse.jdt.annotation.Nullable; */ @NonNullByDefault public record Blocking(boolean blocking, @Nullable Long timer) { - public static Blocking BLOCK = new Blocking(true, null); + public static final Blocking BLOCK = new Blocking(true, null); } diff --git a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/ConfigAnswer.java b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/ConfigAnswer.java index 48bf383a2b..b05b4bc845 100644 --- a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/ConfigAnswer.java +++ b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/ConfigAnswer.java @@ -70,10 +70,14 @@ public record ConfigAnswer(Config config, double took) { public record RateLimit(int count, int interval) { } + public record Domain(String name, boolean local) { + + } + public record Dns(List upstreams, boolean cNAMEdeepInspect, boolean blockESNI, boolean edns0ecs, boolean ignoreLocalhost, boolean showDNSSEC, boolean analyzeOnlyAandAAAA, String piholePTR, String replyWhenBusy, int blockTTL, List hosts, boolean domainNeeded, boolean expandHosts, - String domain, boolean bogusPriv, boolean dnssec, String _interface, String hostRecord, + Domain domain, boolean bogusPriv, boolean dnssec, String _interface, String hostRecord, String listeningMode, boolean queryLogging, List cnameRecords, int port, List revServers, Cache cache, Blocking blocking, SpecialDomains specialDomains, Reply reply, RateLimit rateLimit) { } diff --git a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/SessionAnswer.java b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/SessionAnswer.java index b57697d66c..b574145e21 100644 --- a/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/SessionAnswer.java +++ b/bundles/org.openhab.binding.pihole/src/main/java/org/openhab/binding/pihole/internal/rest/model/v6/SessionAnswer.java @@ -13,12 +13,13 @@ package org.openhab.binding.pihole.internal.rest.model.v6; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; /** * @author Gaƫl L'hopital - Initial contribution */ @NonNullByDefault -public record SessionAnswer(Session session, double took) { +public record SessionAnswer(@Nullable Session session, double took) { public record Session(boolean valid, boolean totp, String sid, String csrf, int validity, String message) { public int cautiousValidity() { return validity / 3 * 2; diff --git a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/i18n/pihole.properties b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/i18n/pihole.properties index 757af4a58d..dc2506b9a9 100644 --- a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/i18n/pihole.properties +++ b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/i18n/pihole.properties @@ -85,7 +85,7 @@ channel-type.pihole.number-channel.label = Number channel channel.ads_blocked_today.label = Ads Blocked Today channel.ads_blocked_today.description = The number of ads blocked today. -channel.ads_percentage_today.label = Ads Percentage Today +channel.ads_percentage_today.label = Ads Today channel.ads_percentage_today.description = The percentage of ads blocked today. channel.clients_ever_seen.label = Clients Ever Seen channel.clients_ever_seen.description = The total number of unique clients ever seen. diff --git a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/thing/thing-types.xml index 9cc3c89e5d..ef7d2e14d1 100644 --- a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/thing/thing-types.xml @@ -21,8 +21,8 @@ The number of ads blocked today. - - + + The percentage of ads blocked today. @@ -117,7 +117,7 @@ - 1 + 2 @@ -154,6 +154,11 @@ + + Number:Dimensionless + + + Switch diff --git a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/gravity.xml b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/update.xml similarity index 76% rename from bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/gravity.xml rename to bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/update.xml index 0b184c1686..42f72d2639 100644 --- a/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/gravity.xml +++ b/bundles/org.openhab.binding.pihole/src/main/resources/OH-INF/update/update.xml @@ -13,4 +13,11 @@ + + + + pihole:percentage-channel + + +