Skip to content

Commit

Permalink
fixes for @clinique code review openhab#3
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent ARNAL <[email protected]>
  • Loading branch information
lo92fr committed Dec 17, 2024
1 parent 6624d2d commit c117259
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 48 deletions.
8 changes: 4 additions & 4 deletions bundles/org.openhab.binding.linky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ The binding will not provide these informations unless this step is ok.
This new binding version is able to use multiple bridge to access the consumption data.
You can use :

- The EnedisWebBridge : this one will use the old Enedis API, base on the enedis web site to gather the data.
- The MyElectricalDataBridge : this one will use the new Rest Enedis API. We will use the MyElectricalData proxy site to access the data.
- The EnedisBridge : this one will also use the new Rest Enedis API, and will directly gather data from Enedis Site.
- The enedis-web bridge : this one will use the old Enedis API, base on the enedis web site to gather the data.
- The myelectricaldata bridge : this one will use the new Rest Enedis API. We will use the MyElectricalData proxy site to access the data.
- The enedis bridge : this one will also use the new Rest Enedis API, and will directly gather data from Enedis Site.

There is advantage and disadvantage for each method.

- EnedisWebBridge is the old way to go.
- enedis-web bridge is the old way to go.

## Supported Things

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class LinkyAuthServlet extends HttpServlet {
private static final String KEY_CB_DISPLAY_INSTRUCTION = "cb.displayInstruction";
private static final String KEY_ERROR = "error";
private static final String KEY_PAGE_REFRESH = "pageRefresh";
private static final String TEMPLATE_PATH = "templates/";

private final Logger logger = LoggerFactory.getLogger(LinkyAuthServlet.class);
private final String index;
Expand All @@ -79,8 +80,6 @@ public class LinkyAuthServlet extends HttpServlet {
private final String myelectricaldataStep2;
private final String myelectricaldataStep3;

private static final String TEMPLATE_PATH = "templates/";

private ApiBridgeHandler apiBridgeHandler;

public LinkyAuthServlet(ApiBridgeHandler apiBridgeHandler) throws LinkyException {
Expand Down Expand Up @@ -239,7 +238,7 @@ private void handleLinkyRedirect(Map<String, String> replaceMap, String servletB
try {
replaceMap.put(KEY_AUTHORIZED_USER, String.format(HTML_USER_AUTHORIZED,
reqCode + " / " + apiBridgeHandler.authorize(servletBaseURL, reqState, reqCode)));
} catch (RuntimeException e) {
} catch (LinkyException e) {
logger.debug("Exception during authorizaton: ", e);
replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.linky.internal;

import static org.openhab.binding.linky.internal.LinkyBindingConstants.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -100,24 +102,24 @@ public LinkyHandlerFactory(final @Reference LocaleProvider localeProvider,

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return LinkyBindingConstants.SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID);
return SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID);
}

@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
if (LinkyBindingConstants.THING_TYPE_API_ENEDIS_BRIDGE.equals(thing.getThingTypeUID())) {
if (THING_TYPE_API_ENEDIS_BRIDGE.equals(thing.getThingTypeUID())) {
EnedisBridgeHandler handler = new EnedisBridgeHandler((Bridge) thing, this.httpClientFactory,
this.oAuthFactory, this.httpService, thingRegistry, componentContext, gson);
return handler;
} else if (LinkyBindingConstants.THING_TYPE_API_WEB_ENEDIS_BRIDGE.equals(thing.getThingTypeUID())) {
} else if (THING_TYPE_API_WEB_ENEDIS_BRIDGE.equals(thing.getThingTypeUID())) {
EnedisWebBridgeHandler handler = new EnedisWebBridgeHandler((Bridge) thing, this.httpClientFactory,
this.oAuthFactory, this.httpService, thingRegistry, componentContext, gson);
return handler;
} else if (LinkyBindingConstants.THING_TYPE_API_MYELECTRICALDATA_BRIDGE.equals(thing.getThingTypeUID())) {
} else if (THING_TYPE_API_MYELECTRICALDATA_BRIDGE.equals(thing.getThingTypeUID())) {
MyElectricalDataBridgeHandler handler = new MyElectricalDataBridgeHandler((Bridge) thing,
this.httpClientFactory, this.oAuthFactory, this.httpService, thingRegistry, componentContext, gson);
return handler;
} else if (LinkyBindingConstants.THING_TYPE_LINKY.equals(thing.getThingTypeUID())) {
} else if (THING_TYPE_LINKY.equals(thing.getThingTypeUID())) {
LinkyHandler handler = new LinkyHandler(thing, localeProvider);
return handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
*/

public class TempoResponse extends LinkedHashMap<String, String> {
@java.io.Serial
private static final long serialVersionUID = 362498820763181264L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

public class WebPrmInfo {
public class Adresse {
public Object adresseLigneUn;
public String adresseLigneUn;
public String adresseLigneDeux;
public Object adresseLigneTrois;
public String adresseLigneTrois;
public String adresseLigneQuatre;
public Object adresseLigneCinq;
public String adresseLigneCinq;
public String adresseLigneSix;
public String adresseLigneSept;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public String authorize(String redirectUri, String reqState, String reqCode) thr
logger.debug("Acces token: {}", accessToken);
return accessToken;
} catch (RuntimeException | OAuthException | IOException e) {
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
throw new LinkyException("Error during oAuth authorize :" + e.getMessage(), e);
} catch (final OAuthResponseException e) {
throw new LinkyException("\"Error during oAuth authorize :" + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public EnedisBridgeHandler(Bridge bridge, final @Reference HttpClientFactory htt
super(bridge, httpClientFactory, oAuthFactory, httpService, thingRegistry, componentContext, gson);
}

@Override
public void initialize() {
super.initialize();
}

@Override
public String getClientId() {
return config.clientId;
Expand All @@ -77,7 +72,7 @@ public String getClientSecret() {

@Override
public void dispose() {
logger.debug("Shutting down Netatmo API bridge handler.");
logger.debug("Shutting down Enedis bridge handler.");

super.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
<description>Authentication ID delivered after the captcha (see documentation).</description>
</parameter>
</config-description>

</bridge-type>


<bridge-type id="my-electrical-data">
<label>MyElectricalDataBridge</label>
<description>
Expand All @@ -66,7 +64,6 @@
</bridge-type>

<thing-type id="linky">

<supported-bridge-type-refs>
<bridge-type-ref id="enedis"/>
<bridge-type-ref id="enedis-web"/>
Expand All @@ -80,7 +77,6 @@
https://espace-client-particuliers.enedis.fr/web/espace-particuliers/compteur-linky.
</description>


<channel-groups>
<channel-group typeId="main" id="main"/>
<channel-group typeId="tempo" id="tempo"/>
Expand All @@ -91,9 +87,6 @@
<channel-group typeId="yearly" id="yearly"/>
</channel-groups>




<config-description>
<parameter name="prmId" type="text" required="true">
<label>prmId</label>
Expand All @@ -105,22 +98,19 @@
http://youopenhab/connectlinky)</description>
</parameter>
</config-description>


</thing-type>


<channel-group-type id="loadCurve">
<label>Load curve</label>
<channels>
<channel id="power" typeId="power">
<label>Load Curve power</label>
<label>Load Curve Power</label>
</channel>
</channels>
</channel-group-type>

<channel-group-type id="daily">
<label>Daily consumption</label>
<label>Daily Consumption</label>
<channels>
<channel id="yesterday" typeId="consumption">
<label>Yesterday Consumption</label>
Expand All @@ -135,13 +125,11 @@
<label>Consumption</label>
</channel>


<channel id="maxPower" typeId="power">
<label>Peak Value</label>
<description>Maximum power usage value</description>
</channel>


<channel id="power" typeId="power">
<label>Peak Value Yesterday</label>
<description>Maximum power usage value for Yesterday</description>
Expand Down Expand Up @@ -172,7 +160,7 @@
</channel-group-type>

<channel-group-type id="weekly">
<label>Weekly consumption</label>
<label>Weekly Consumption</label>
<channels>
<channel id="thisWeek" typeId="consumption">
<label>This Week Consumption</label>
Expand All @@ -194,7 +182,7 @@
</channel-group-type>

<channel-group-type id="monthly">
<label>Monthly consumption</label>
<label>Monthly Consumption</label>
<channels>
<channel id="thisMonth" typeId="consumption">
<label>This Month Consumption</label>
Expand All @@ -216,7 +204,7 @@
</channel-group-type>

<channel-group-type id="yearly">
<label>Yearly consumption</label>
<label>Yearly Consumption</label>
<channels>
<channel id="thisYear" typeId="consumption">
<label>This Year Consumption</label>
Expand All @@ -241,20 +229,19 @@
<label>Tempo</label>
<channels>
<channel id="tempoInfoToday" typeId="tempoValue">
<label>Tempo Today color</label>
<label>Tempo Today Color</label>
</channel>
<channel id="tempoInfoTomorrow" typeId="tempoValue">
<label>Tempo Today color</label>
<label>Tempo Today Color</label>
</channel>
<channel id="tempoInfoTimeSeries" typeId="tempoValue">
<label>Tempo day information</label>
<label>Tempo Day Information</label>
</channel>
</channels>
</channel-group-type>

<channel-group-type id="main">
<label>Main</label>

<channels>
<channel id="identity" typeId="info">
<label>Identity</label>
Expand Down Expand Up @@ -322,7 +309,7 @@

<channel-type id="tempoValue">
<item-type>Number</item-type>
<label>Tempo color information</label>
<label>Tempo Color Information</label>
<description>This status describes the tempo color of a day.</description>
<state>
<options>
Expand All @@ -348,7 +335,6 @@
<state readOnly="true" pattern="%1$tF"/>
</channel-type>


<channel-type id="consumption">
<item-type>Number:Energy</item-type>
<label>Total Consumption</label>
Expand All @@ -370,6 +356,4 @@
<category>time</category>
<state readOnly="true"/>
</channel-type>


</thing:thing-descriptions>

0 comments on commit c117259

Please sign in to comment.