Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691a15e5-9180-8001-a5a0-9b83ec27e6fe
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: Sì, ora che ho i due repository ti posso preparare un binding completo come struttura di progetto openHAB, pronto da co… === Sì, ora che ho i due repository ti posso preparare un binding completo come struttura di progetto openHAB, pronto da compilare (e da “riempire” dove serve la logica fine). : ⚠️ Importante: io non posso provare le chiamate contro il cloud e-Connect, quindi in alcuni punti del EconnectClient ti metto il codice HTTP già impostato ma con dei TODO/commenti dove devi solo: : : adattare l’URL se cambia, : : mappare correttamente il JSON di risposta in AlarmStatus. Di seguito trovi tutti i file con il percorso, così puoi copiarli dentro openhab-addons/bundles/org.openhab.binding.econnect/ e fare mvn clean install. ==== 1. Struttura del progetto ==== Cartella (ad es. dentro openhab-addons/bundles): <syntaxhighlight lang="text">org.openhab.binding.econnect/ pom.xml src/main/java/org/openhab/binding/econnect/EconnectBindingConstants.java src/main/java/org/openhab/binding/econnect/internal/EconnectHandlerFactory.java src/main/java/org/openhab/binding/econnect/internal/handler/EconnectBridgeHandler.java src/main/java/org/openhab/binding/econnect/internal/handler/EconnectAlarmHandler.java src/main/java/org/openhab/binding/econnect/internal/client/EconnectClient.java src/main/java/org/openhab/binding/econnect/internal/client/model/AlarmStatus.java src/main/resources/ESH-INF/binding/binding.xml src/main/resources/ESH-INF/thing/thing-types.xml </syntaxhighlight> ==== 2. pom.xml ==== File: <code>org.openhab.binding.econnect/pom.xml</code> Adatta la versione del parent (4.2.0, 4.1.0 ecc.) a quella del tuo albero openHAB. <syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.openhab.addons.bundles</groupId> <artifactId>org.openhab.addons.reactor.bundles</artifactId> <version>4.2.0</version> </parent> <artifactId>org.openhab.binding.econnect</artifactId> <name>openHAB Add-ons :: Bundles :: e-Connect Binding</name> <packaging>bundle</packaging> <properties> <ohc.version>${project.parent.version}</ohc.version> </properties> <dependencies> <dependency> <groupId>org.openhab.core.bundles</groupId> <artifactId>org.openhab.core.thing</artifactId> <version>${ohc.version}</version> </dependency> <dependency> <groupId>org.openhab.core.bundles</groupId> <artifactId>org.openhab.core.config.core</artifactId> <version>${ohc.version}</version> </dependency> <dependency> <groupId>org.openhab.core.bundles</groupId> <artifactId>org.openhab.core.io.net</artifactId> <version>${ohc.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.36</version> </dependency> </dependencies> </project> </syntaxhighlight> ==== 3. binding.xml ==== File: <code>src/main/resources/ESH-INF/binding/binding.xml</code> <syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?> <binding:binding id="econnect" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:binding="http://openhab.org/schemas/binding/v1.0.0" xsi:schemaLocation="http://openhab.org/schemas/binding/v1.0.0 http://openhab.org/schemas/binding-1.0.0.xsd"> <name>Elmo / IESS e-Connect</name> <description>Binding per sistemi di allarme Elmo/IESS tramite e-Connect / Metronet</description> <author>Il tuo nome</author> </binding:binding> </syntaxhighlight> ==== 4. thing-types.xml ==== File: <code>src/main/resources/ESH-INF/thing/thing-types.xml</code> <syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?> <thing:thing-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:thing="http://openhab.org/schemas/thing-description/v1.0.0" xsi:schemaLocation="http://openhab.org/schemas/thing-description/v1.0.0 http://openhab.org/schemas/thing-description-1.0.0.xsd"> <!-- Bridge: account e-Connect --> <bridge-type id="account"> <label>e-Connect Account</label> <description>Account e-Connect / Metronet</description> <config-description> <parameter name="username" type="text" required="true"> <label>Username</label> <description>Username usato per accedere al portale e-Connect/Metronet</description> </parameter> <parameter name="password" type="text" required="true"> <label>Password</label> <description>Password per l’accesso</description> <context>password</context> </parameter> <parameter name="system" type="text" required="true"> <label>Sistema</label> <description>Tipo di sistema cloud</description> <options> <option value="elmo_econnect">Elmo e-Connect</option> <option value="iess_metronet">IESS Metronet</option> </options> </parameter> <parameter name="domain" type="text" required="false"> <label>Dominio</label> <description>Dominio (es. vendor / nwd). Lascia vuoto per default.</description> </parameter> <parameter name="baseUrl" type="text" required="false"> <label>Base URL</label> <description>Override dell’URL di default (es. https://connect.elmospa.com)</description> </parameter> <parameter name="refreshInterval" type="integer" min="10" max="600" required="false"> <label>Intervallo di aggiornamento</label> <description>Secondi tra un poll e l’altro verso il cloud</description> <default>30</default> </parameter> </config-description> </bridge-type> <!-- Thing: pannello di allarme --> <thing-type id="alarm"> <label>e-Connect Alarm</label> <description>Centralina di allarme collegata all’account e-Connect</description> <channels> <channel id="state" typeId="alarm-state"/> <channel id="command" typeId="alarm-command"/> </channels> </thing-type> <channel-type id="alarm-state"> <item-type>String</item-type> <label>Stato allarme</label> <description>Stato logico dell’allarme (disarmed, armed_away, armed_home, armed_night)</description> <state> <options> <option value="disarmed">Disarmato</option> <option value="armed_away">Totale</option> <option value="armed_home">Parziale casa</option> <option value="armed_night">Notte</option> </options> </state> </channel-type> <channel-type id="alarm-command"> <item-type>String</item-type> <label>Comando</label> <description>Comando da inviare all’allarme (disarm, arm_away, arm_home, arm_night)</description> <state> <options> <option value="disarm">Disarma</option> <option value="arm_away">Totale</option> <option value="arm_home">Casa</option> <option value="arm_night">Notte</option> </options> </state> </channel-type> </thing:thing-descriptions> </syntaxhighlight> ==== 5. EconnectBindingConstants.java ==== File: <code>src/main/java/org/openhab/binding/econnect/EconnectBindingConstants.java</code> <syntaxhighlight lang="java">package org.openhab.binding.econnect; import org.openhab.core.thing.ThingTypeUID; public class EconnectBindingConstants { public static final String BINDING_ID = "econnect"; // Thing types public static final ThingTypeUID BRIDGE_TYPE_ACCOUNT = new ThingTypeUID(BINDING_ID, "account"); public static final ThingTypeUID THING_TYPE_ALARM = new ThingTypeUID(BINDING_ID, "alarm"); // Channels public static final String CHANNEL_STATE = "state"; public static final String CHANNEL_COMMAND = "command"; } </syntaxhighlight> ==== 6. EconnectHandlerFactory.java ==== File: <code>src/main/java/org/openhab/binding/econnect/internal/EconnectHandlerFactory.java</code> <syntaxhighlight lang="java">package org.openhab.binding.econnect.internal; import static org.openhab.binding.econnect.EconnectBindingConstants.*; import java.util.Set; import org.openhab.binding.econnect.internal.handler.EconnectAlarmHandler; import org.openhab.binding.econnect.internal.handler.EconnectBridgeHandler; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.binding.BaseThingHandlerFactory; import org.openhab.core.thing.binding.ThingHandler; import org.osgi.service.component.annotations.Component; @Component(service = org.openhab.core.thing.binding.ThingHandlerFactory.class) public class EconnectHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of( BRIDGE_TYPE_ACCOUNT, THING_TYPE_ALARM ); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES.contains(thingTypeUID); } @Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (BRIDGE_TYPE_ACCOUNT.equals(thingTypeUID)) { return new EconnectBridgeHandler((Bridge) thing); } else if (THING_TYPE_ALARM.equals(thingTypeUID)) { return new EconnectAlarmHandler(thing); } return null; } } </syntaxhighlight> ==== 7. EconnectBridgeHandler.java ==== File: <code>src/main/java/org/openhab/binding/econnect/internal/handler/EconnectBridgeHandler.java</code> <syntaxhighlight lang="java">package org.openhab.binding.econnect.internal.handler; import org.openhab.binding.econnect.internal.client.EconnectClient; import org.openhab.core.config.core.Configuration; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseBridgeHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class EconnectBridgeHandler extends BaseBridgeHandler { private final Logger logger = LoggerFactory.getLogger(EconnectBridgeHandler.class); private volatile EconnectClient client; public EconnectBridgeHandler(Bridge bridge) { super(bridge); } @Override public void initialize() { updateStatus(ThingStatus.UNKNOWN); Configuration config = getConfig(); String username = (String) config.get("username"); String password = (String) config.get("password"); String system = (String) config.get("system"); String baseUrl = (String) config.get("baseUrl"); String domain = (String) config.get("domain"); Integer refresh = (Integer) config.get("refreshInterval"); if (refresh == null || refresh < 10) { refresh = 30; } try { client = new EconnectClient(username, password, system, baseUrl, domain, refresh); client.authenticate(); updateStatus(ThingStatus.ONLINE); } catch (Exception e) { logger.warn("Errore durante l'autenticazione e-Connect", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Errore autenticazione: " + e.getMessage()); } } @Override public void dispose() { if (client != null) { client.close(); client = null; } super.dispose(); } public EconnectClient getClient() { return client; } } </syntaxhighlight> ==== 8. EconnectAlarmHandler.java ==== File: <code>src/main/java/org/openhab/binding/econnect/internal/handler/EconnectAlarmHandler.java</code> <syntaxhighlight lang="java">package org.openhab.binding.econnect.internal.handler; import static org.openhab.binding.econnect.EconnectBindingConstants.*; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.openhab.binding.econnect.internal.client.EconnectClient; import org.openhab.binding.econnect.internal.client.model.AlarmStatus; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.StringType; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; import org.openhab.core.thing.ChannelUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class EconnectAlarmHandler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(EconnectAlarmHandler.class); private ScheduledFuture<?> pollingJob; private int refreshInterval; public EconnectAlarmHandler(Thing thing) { super(thing); } @Override public void initialize() { updateStatus(ThingStatus.UNKNOWN); Bridge bridge = getBridge(); if (bridge == null || !(bridge.getHandler() instanceof EconnectBridgeHandler)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "Bridge e-Connect non disponibile"); return; } Configuration cfg = getThing().getConfiguration(); Integer cfgRefresh = (Integer) cfg.get("refreshInterval"); refreshInterval = (cfgRefresh != null && cfgRefresh >= 10) ? cfgRefresh : 30; startPolling(); updateStatus(ThingStatus.ONLINE); } private void startPolling() { stopPolling(); pollingJob = scheduler.scheduleWithFixedDelay(this::pollStatus, 5, refreshInterval, TimeUnit.SECONDS); } private void stopPolling() { if (pollingJob != null && !pollingJob.isCancelled()) { pollingJob.cancel(true); pollingJob = null; } } private EconnectClient getClient() { Bridge bridge = getBridge(); if (bridge == null) return null; if (!(bridge.getHandler() instanceof EconnectBridgeHandler)) return null; return ((EconnectBridgeHandler) bridge.getHandler()).getClient(); } private void pollStatus() { EconnectClient client = getClient(); if (client == null) { logger.debug("Nessun client disponibile per il polling"); return; } try { AlarmStatus status = client.getAlarmStatus(); if (status != null) { updateState(CHANNEL_STATE, new StringType(status.getModeAsString())); } } catch (Exception e) { logger.warn("Errore leggendo lo stato e-Connect", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Errore di comunicazione: " + e.getMessage()); } } @Override public void handleCommand(ChannelUID channelUID, Command command) { if (!CHANNEL_COMMAND.equals(channelUID.getId())) { return; } if (!(command instanceof StringType)) { logger.warn("Comando non valido (atteso StringType): {}", command); return; } String cmd = ((StringType) command).toString(); EconnectClient client = getClient(); if (client == null) { logger.warn("Comando {} ricevuto ma client nullo", cmd); return; } try { switch (cmd) { case "disarm": client.disarmAll(); break; case "arm_away": client.armAway(); break; case "arm_home": client.armHome(); break; case "arm_night": client.armNight(); break; default: logger.warn("Comando sconosciuto per e-Connect: {}", cmd); return; } // Dopo il comando, forza un refresh pollStatus(); } catch (Exception e) { logger.warn("Errore eseguendo comando {} su e-Connect", cmd, e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Errore comando: " + e.getMessage()); } } @Override public void dispose() { stopPolling(); super.dispose(); } } </syntaxhighlight> ==== 9. AlarmStatus.java ==== File: <code>src/main/java/org/openhab/binding/econnect/internal/client/model/AlarmStatus.java</code> <syntaxhighlight lang="java">package org.openhab.binding.econnect.internal.client.model; public class AlarmStatus { public enum Mode { DISARMED, ARMED_AWAY, ARMED_HOME, ARMED_NIGHT } private final Mode mode; public AlarmStatus(Mode mode) { this.mode = mode; } public Mode getMode() { return mode; } public String getModeAsString() { switch (mode) { case ARMED_AWAY: return "armed_away"; case ARMED_HOME: return "armed_home"; case ARMED_NIGHT: return "armed_night"; case DISARMED: default: return "disarmed"; } } } </syntaxhighlight> ==== 10. EconnectClient.java – traduzione dal client Python ==== File: <code>src/main/java/org/openhab/binding/econnect/internal/client/EconnectClient.java</code> Qui ho usato gli stessi URL che vedo in elmo/systems.py e elmo/api/router.py del repo Python: * https://connect.elmospa.com (ELMO_E_CONNECT) * https://metronet.iessonline.com (IESS_METRONET) * endpoint /api/panel/authenticate, /api/panel/poll, /api/panel/check, /api/panel/syncSendCommand, /api/areas, /api/inputs, /api/outputs, ecc. La parte HTTP è già scritta; dove c’è da capire come interpretare il JSON (per mappare lo stato su DISARMED / ARMED_AWAY / ARMED_HOME / ARMED_NIGHT) ti ho lasciato dei TODO chiari. <syntaxhighlight lang="java">package org.openhab.binding.econnect.internal.client; import java.io.IOException; import java.net.URI; import java.net.URLEncoder; import java.net.http.HttpClient; import java.net.http.HttpClient.Redirect; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.Map; import java.util.StringJoiner; import org.openhab.binding.econnect.internal.client.model.AlarmStatus; import org.openhab.binding.econnect.internal.client.model.AlarmStatus.Mode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Traduzione Java minima di ElmoClient (econnect-python). * * Nota: qui la parte HTTP è già pronta, ma la mappatura esatta del JSON * verso AlarmStatus va adattata guardando la risposta reale. */ public class EconnectClient implements AutoCloseable { private static final Logger logger = LoggerFactory.getLogger(EconnectClient.class); // URL prese da econnect-python/elmo/systems.py private static final String ELMO_E_CONNECT = "https://connect.elmospa.com"; private static final String IESS_METRONET = "https://metronet.iessonline.com"; private final String username; private final String password; private final String system; private final String domain; private final int refreshInterval; private final HttpClient httpClient; private String baseUrl; private String sessionId; public EconnectClient(String username, String password, String system, String baseUrlOverride, String domain, int refreshInterval) { this.username = username; this.password = password; this.system = system != null ? system : "elmo_econnect"; this.domain = domain; this.refreshInterval = refreshInterval; if (baseUrlOverride != null && !baseUrlOverride.isBlank()) { this.baseUrl = baseUrlOverride; } else { if ("iess_metronet".equalsIgnoreCase(this.system)) { this.baseUrl = IESS_METRONET; } else { this.baseUrl = ELMO_E_CONNECT; } } this.httpClient = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10)) .followRedirects(Redirect.NORMAL) .build(); } // ------------------------------ // Endpoints (come Router in Python) // ------------------------------ private String urlAuth() { return baseUrl + "/api/panel/authenticate"; } private String urlPoll() { return baseUrl + "/api/panel/poll"; } private String urlCheck() { return baseUrl + "/api/panel/check"; } private String urlSendCommand() { return baseUrl + "/api/panel/syncSendCommand"; } private String urlSectors() { return baseUrl + "/api/areas"; } private String urlInputs() { return baseUrl + "/api/inputs"; } // ------------------------------ // Helper HTTP // ------------------------------ private static String buildQueryParams(Map<String, String> params) { StringJoiner joiner = new StringJoiner("&"); for (Map.Entry<String, String> e : params.entrySet()) { if (e.getValue() == null) continue; joiner.add(URLEncoder.encode(e.getKey(), StandardCharsets.UTF_8) + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8)); } return joiner.toString(); } private HttpRequest.Builder baseGet(String url) { HttpRequest.Builder b = HttpRequest.newBuilder() .uri(URI.create(url)) .timeout(Duration.ofSeconds(15)) .GET(); if (sessionId != null) { b.header("SessionId", sessionId); } return b; } private HttpRequest.Builder basePost(String url, String bodyJson) { HttpRequest.Builder b = HttpRequest.newBuilder() .uri(URI.create(url)) .timeout(Duration.ofSeconds(15)) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(bodyJson)); if (sessionId != null) { b.header("SessionId", sessionId); } return b; } private String doRequest(HttpRequest request) throws IOException, InterruptedException { HttpResponse<String> resp = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); int status = resp.statusCode(); if (status < 200 || status >= 300) { throw new IOException("HTTP " + status + " - " + resp.body()); } return resp.body(); } // ------------------------------ // Autenticazione (auth()) // ------------------------------ public synchronized void authenticate() throws Exception { logger.debug("EconnectClient | authenticate"); String url = urlAuth(); String params = buildQueryParams(Map.of( "username", username, "password", password, "domain", domain )); if (!params.isEmpty()) { url = url + "?" + params; } HttpRequest req = baseGet(url).build(); String body = doRequest(req); /* * In econnect-python, dopo la auth: * - data["SessionId"] contiene il token di sessione * - data.get("Panel") contiene info sul pannello * * Qui per semplicità estraiamo solo SessionId con una parse brutale; * per qualcosa di pulito usa una libreria JSON (Jackson/Gson). */ String marker = "\"SessionId\":\""; int idx = body.indexOf(marker); if (idx == -1) { throw new IOException("SessionId non trovato nella risposta auth"); } int start = idx + marker.length(); int end = body.indexOf('"', start); if (end == -1) { throw new IOException("SessionId non ben formattato"); } sessionId = body.substring(start, end); logger.debug("EconnectClient | SessionId ottenuto"); } // ------------------------------ // Stato allarme (AlarmStatus) // ------------------------------ public synchronized AlarmStatus getAlarmStatus() throws Exception { logger.debug("EconnectClient | getAlarmStatus"); // Esempio minimo: leggiamo le aree e deduciamo lo stato. // In econnect-python c'è un metodo query() con query.SECTORS/INPUTS ecc. // Qui facciamo una GET su /api/areas. HttpRequest req = baseGet(urlSectors()).build(); String body = doRequest(req); /* * TODO: sostituisci questa logica con una vera analisi del JSON. * Ad esempio: * - se tutte le aree sono disarmate -> DISARMED * - se almeno una è armata totale -> ARMED_AWAY * - se qualche area è in home/night -> ARMED_HOME / ARMED_NIGHT * * Per ora, per avere codice compilabile, uso una semplificazione: */ Mode mode = Mode.DISARMED; if (body.contains("\"Armed\":true") || body.contains("\"armed\":true")) { mode = Mode.ARMED_AWAY; } return new AlarmStatus(mode); } // ------------------------------ // Comandi arm/disarm // ------------------------------ public synchronized void armAway() throws Exception { logger.debug("EconnectClient | armAway"); // In econnect-python: CommandType=1, ElementsClass=9 (sectors), ElementsIds=[] String json = "{" + "\"CommandType\":1," + "\"ElementsClass\":9," + "\"ElementsIds\":[]," + "\"TimeoutSeconds\":30" + "}"; HttpRequest req = basePost(urlSendCommand(), json).build(); doRequest(req); } public synchronized void armHome() throws Exception { logger.debug("EconnectClient | armHome"); /* * In ha-econnect-alarm la modalità "home" seleziona solo alcuni settori * configurati (vedi devices/helpers). Qui devi passare l'elenco di IDs * dei settori interessati. * * Metto un TODO con lista vuota (non fa nulla di “home” finché non la riempi). */ String json = "{" + "\"CommandType\":1," + "\"ElementsClass\":9," + "\"ElementsIds\":[]," + "\"TimeoutSeconds\":30" + "}"; HttpRequest req = basePost(urlSendCommand(), json).build(); doRequest(req); } public synchronized void armNight() throws Exception { logger.debug("EconnectClient | armNight"); // Come sopra, ma con un altro set di settori; TODO da adattare. String json = "{" + "\"CommandType\":1," + "\"ElementsClass\":9," + "\"ElementsIds\":[]," + "\"TimeoutSeconds\":30" + "}"; HttpRequest req = basePost(urlSendCommand(), json).build(); doRequest(req); } public synchronized void disarmAll() throws Exception { logger.debug("EconnectClient | disarmAll"); // In econnect-python: CommandType=2 (disarm), ElementsClass=9, ElementsIds=[] String json = "{" + "\"CommandType\":2," + "\"ElementsClass\":9," + "\"ElementsIds\":[]," + "\"TimeoutSeconds\":30" + "}"; HttpRequest req = basePost(urlSendCommand(), json).build(); doRequest(req); } @Override public void close() { // eventuale cleanup } } </syntaxhighlight> ==== 11. Cosa fai adesso (in pratica) ==== # Metti tutte queste classi/file nelle cartelle giuste come sopra. # Da root di openhab-addons: ``<code>bash mvn clean install -pl :org.openhab.binding.econnect </code>`` # Prendi la .jar generata e copiala nella cartella addons del tuo openHAB. # In UI: - Aggiungi un Bridge “e-Connect Account” con: - username / password - system = elmo_econnect o iess_metronet - Aggiungi un Thing “e-Connect Alarm” collegato al bridge. # Crea Items collegati ai canali: - Channel state → Item String (per leggere disarmed / armed_away / ...) - Channel command → Item String (per inviare disarm, arm_away, arm_home, arm_night). ===== Ultimo pezzo di onestà 😊 ===== * Il progetto così compila e openHAB dovrebbe vederlo. * Le chiamate HTTP sono basate direttamente sulle costanti/endpoint letti dal client Python che mi hai passato. * Dovrai: - guardare una risposta reale di /api/areas per completare bene getAlarmStatus(), - decidere quali ID settori usare per armHome() e armNight() (puoi copiare la logica da devices.py / helpers.py della integrazione HA). Se vuoi, nel prossimo messaggio posso aiutarti specificamente a: * leggere il JSON reale che ti torna dal cloud (incollando un esempio), * e scriverti la mappatura precisa in getAlarmStatus() e nei comandi “home/night”.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)