Skip to content

Commit

Permalink
Merge branch 'openhab:main' into discovery-mthods-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfg authored Nov 29, 2023
2 parents 3b07910 + b80273a commit c0dd8a9
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 101 deletions.
8 changes: 4 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@
/bundles/org.openhab.binding.modbus.sunspec/ @mrbig
/bundles/org.openhab.binding.monopriceaudio/ @mlobstein
/bundles/org.openhab.binding.mpd/ @stefanroellin
/bundles/org.openhab.binding.mqtt/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.mqtt/ @ccutrer
/bundles/org.openhab.binding.mqtt.espmilighthub/ @Skinah
/bundles/org.openhab.binding.mqtt.generic/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.mqtt.homeassistant/ @antroids
/bundles/org.openhab.binding.mqtt.homie/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.mqtt.generic/ @ccutrer
/bundles/org.openhab.binding.mqtt.homeassistant/ @antroids @ccutrer
/bundles/org.openhab.binding.mqtt.homie/ @ccutrer
/bundles/org.openhab.binding.mqtt.ruuvigateway/ @ssalonen
/bundles/org.openhab.binding.mycroft/ @dalgwen
/bundles/org.openhab.binding.mybmw/ @weymann @ntruchsess
Expand Down
22 changes: 15 additions & 7 deletions bundles/org.openhab.binding.ecowatt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@ You have to add the thing manually.

You must create an account and an application on the RTE portal to obtain the OAuth2 credentials required to access the API.

1. Open this [page](https://data.rte-france.com/catalog/-/api/consumption/Ecowatt/v4.0), find the "Ecowatt" tile and click on the "Abonnez-vous à l'API" button.
1. Open this [page](https://data.rte-france.com/catalog/-/api/consumption/Ecowatt/v5.0), find the "Ecowatt" tile and click on the "Abonnez-vous à l'API" button.
1. Create an account by following the instructions (you will receive an email to validate your new account).
1. Once logged in, create an application by entering a name (for example "openHAB Integration"), choosing "Web Server" as type, entering any description of your choice and finally clicking on the "Valider" button.
1. You will then see your application details, in particular the "ID client" and "ID Secret" information which you will need later to set up your binding thing.

Note that you are subscribed to a particular version of the API.
When a new version of the API is released, you will have to subscribe to this new version and create a new application.
You will then get new information "ID client" and "ID Secret" and you will have to update your thing configuration in openHAB.
After changing version, you will have to wait for your authentication token to be renewed (max 2 hours) to get a successful response from the API.

## Binding Configuration

There are no overall binding configuration settings that need to be set.
All settings are through thing configuration parameters.

## Thing Configuration

| Name | Type | Description | Required |
|-----------|---------|-----------------------------------------------------------------------|----------|
| idClient | text | ID client provided with the application you created in the RTE portal | yes |
| idSecret | text | ID secret provided with the application you created in the RTE portal | yes |
| Name | Type | Description | Required | Default |
|------------|---------|---------------------------------------------------------------------------|----------|---------|
| apiVersion | integer | The version of the Ecowatt tile to which you subscribed in the RTE portal | no | 4 |
| idClient | text | ID client provided with the application you created in the RTE portal | yes | |
| idSecret | text | ID secret provided with the application you created in the RTE portal | yes | |

Take care to select the API version corresponding to the one to which you subscribed in the RTE portal.

## Channels

Expand All @@ -42,14 +50,14 @@ All channels are read-only.
|-------------------|--------|------------------------------------------------------------------|
| todaySignal | Number | The signal relating to the forecast consumption level for today. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red). |
| tomorrowSignal | Number | The signal relating to the forecast consumption level for tomorrow. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red). |
| currentHourSignal | Number | The signal relating to the forecast consumption level for the current hour. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red). |
| currentHourSignal | Number | The signal relating to the forecast consumption level for the current hour. Values are 0 for normal consumption (green) and carbon-free production, 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red). |

## Full Example

example.things:

```java
Thing ecowatt:signals:signals "Ecowatt Signals" [ idClient="xxxxx", idSecret="yyyyy"]
Thing ecowatt:signals:signals "Ecowatt Signals" [ apiVersion=4, idClient="xxxxx", idSecret="yyyyy"]
```

example.items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
* The {@link EcowattConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Laurent Garnier - Initial contribution
* @author Laurent Garnier - New parameter apiVersion
*/
@NonNullByDefault
public class EcowattConfiguration {

public int apiVersion = 4;
public String idClient = "";
public String idSecret = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* The {@link EcowattHandler} is responsible for updating the state of the channels
*
* @author Laurent Garnier - Initial contribution
* @author Laurent Garnier - Add support for API version 5
*/
@NonNullByDefault
public class EcowattHandler extends BaseThingHandler {
Expand Down Expand Up @@ -100,7 +101,8 @@ public void initialize() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/offline.config-error-unset-parameters");
} else {
api = new EcowattRestApi(oAuthFactory, httpClient, thing.getUID().getAsString(), idClient, idSecret);
api = new EcowattRestApi(oAuthFactory, httpClient, thing.getUID().getAsString(), idClient, idSecret,
config.apiVersion);
updateStatus(ThingStatus.UNKNOWN);
scheduleNextUpdate(0, true);
}
Expand Down Expand Up @@ -264,7 +266,7 @@ public static State getHourSignalState(@Nullable EcowattApiResponse response, Zo
int hour = dateTime.withZoneSameInstant(day.getZone()).getHour();
int value = signals.getHourSignal(hour);
LoggerFactory.getLogger(EcowattHandler.class).debug("hour {} value {}", hour, value);
if (value >= 1 && value <= 3) {
if (value >= 0 && value <= 3) {
return new DecimalType(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public int getHourSignal(int hour) {
}
}
}
return 0;
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,25 @@
* The {@link EcowattRestApi} is responsible for handling all communication with the Ecowatt REST API
*
* @author Laurent Garnier - Initial contribution
* @author Laurent Garnier - Add support for different API versions
*/
@NonNullByDefault
public class EcowattRestApi {

private static final String ECOWATT_API_TOKEN_URL = "https://digital.iservices.rte-france.com/token/oauth/";
private static final String ECOWATT_API_GET_SIGNALS_URL = "https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals";
private static final String ECOWATT_API_GET_SIGNALS_URL = "https://digital.iservices.rte-france.com/open_api/ecowatt/v%d/signals";

private final Logger logger = LoggerFactory.getLogger(EcowattRestApi.class);

private final OAuthFactory oAuthFactory;
private final HttpClient httpClient;
private final Gson gson;
private final String apiUrl;
private OAuthClientService authService;
private String authServiceHandle;

public EcowattRestApi(OAuthFactory oAuthFactory, HttpClient httpClient, String authServiceHandle, String idClient,
String idSecret) {
String idSecret, int apiVersion) {
this.oAuthFactory = oAuthFactory;
this.httpClient = httpClient;
GsonBuilder gsonBuilder = new GsonBuilder();
Expand All @@ -73,13 +75,14 @@ public EcowattRestApi(OAuthFactory oAuthFactory, HttpClient httpClient, String a
this.authService = oAuthFactory.createOAuthClientService(authServiceHandle, ECOWATT_API_TOKEN_URL, null,
idClient, idSecret, null, true);
this.authServiceHandle = authServiceHandle;
this.apiUrl = ECOWATT_API_GET_SIGNALS_URL.formatted(apiVersion);
}

public EcowattApiResponse getSignals() throws CommunicationException, EcowattApiLimitException {
logger.debug("API request signals");
logger.debug("API request {}", apiUrl);
String token = authenticate().getAccessToken();

final Request request = httpClient.newRequest(ECOWATT_API_GET_SIGNALS_URL).method(HttpMethod.GET)
final Request request = httpClient.newRequest(apiUrl).method(HttpMethod.GET)
.header(HttpHeader.AUTHORIZATION, "Bearer " + token).timeout(10, TimeUnit.SECONDS);

ContentResponse response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ addon.ecowatt.description = This binding uses the Ecowatt API to expose clear si
thing-type.ecowatt.signals.label = Electricity Forecast
thing-type.ecowatt.signals.description = The French electricity consumption forecasts
thing-type.ecowatt.signals.channel.currentHourSignal.label = Current Hour Signal
thing-type.ecowatt.signals.channel.currentHourSignal.description = The signal relating to the forecast consumption level for the current hour. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).
thing-type.ecowatt.signals.channel.currentHourSignal.description = The signal relating to the forecast consumption level for the current hour. Values are 0 for normal consumption (green) and carbon-free production, 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).
thing-type.ecowatt.signals.channel.inThreeDaysSignal.label = In Three Days Signal
thing-type.ecowatt.signals.channel.inThreeDaysSignal.description = The signal relating to the forecast consumption level in three days. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).
thing-type.ecowatt.signals.channel.inTwoDaysSignal.label = In Two Days Signal
Expand All @@ -20,6 +20,10 @@ thing-type.ecowatt.signals.channel.tomorrowSignal.description = The signal relat

# thing types config

thing-type.config.ecowatt.signals.apiVersion.label = API Version
thing-type.config.ecowatt.signals.apiVersion.description = The version of the Ecowatt tile to which you subscribed in the RTE portal.
thing-type.config.ecowatt.signals.apiVersion.option.4 = V4.0 (deprecated)
thing-type.config.ecowatt.signals.apiVersion.option.5 = V5.0
thing-type.config.ecowatt.signals.idClient.label = ID Client
thing-type.config.ecowatt.signals.idClient.description = ID client provided with the application you created in the RTE portal.
thing-type.config.ecowatt.signals.idSecret.label = ID Secret
Expand All @@ -28,7 +32,8 @@ thing-type.config.ecowatt.signals.idSecret.description = ID secret provided with
# channel types

channel-type.ecowatt.signal.label = Consumption Signal
channel-type.ecowatt.signal.description = The signal relating to the forecast consumption level. Values are 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).
channel-type.ecowatt.signal.description = The signal relating to the forecast consumption level. Values are 0 for normal consumption (green) and carbon-free production, 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).
channel-type.ecowatt.signal.state.option.0 = Green + carbon-free production
channel-type.ecowatt.signal.state.option.1 = Green
channel-type.ecowatt.signal.state.option.2 = Orange
channel-type.ecowatt.signal.state.option.3 = Red
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@
</channel>
<channel id="currentHourSignal" typeId="signal">
<label>Current Hour Signal</label>
<description>The signal relating to the forecast consumption level for the current hour. Values are 1 for normal
consumption (green), 2 for strained electrical system (orange) and 3 for very strained electrical system (red).</description>
<description>The signal relating to the forecast consumption level for the current hour. Values are 0 for normal
consumption (green) and carbon-free production, 1 for normal consumption (green), 2 for strained electrical system
(orange) and 3 for very strained electrical system (red).</description>
</channel>
</channels>

<config-description>
<parameter name="apiVersion" type="integer" required="false">
<label>API Version</label>
<description>The version of the Ecowatt tile to which you subscribed in the RTE portal.</description>
<options>
<option value="4">V4.0 (deprecated)</option>
<option value="5">V5.0</option>
</options>
<default>4</default>
</parameter>
<parameter name="idClient" type="text" required="true">
<label>ID Client</label>
<description>ID client provided with the application you created in the RTE portal.</description>
Expand All @@ -55,10 +65,12 @@
<channel-type id="signal">
<item-type>Number</item-type>
<label>Consumption Signal</label>
<description>The signal relating to the forecast consumption level. Values are 1 for normal consumption (green), 2 for
strained electrical system (orange) and 3 for very strained electrical system (red).</description>
<description>The signal relating to the forecast consumption level. Values are 0 for normal consumption (green) and
carbon-free production, 1 for normal consumption (green), 2 for strained electrical system (orange) and 3 for very
strained electrical system (red).</description>
<state readOnly="true">
<options>
<option value="0">Green + carbon-free production</option>
<option value="1">Green</option>
<option value="2">Orange</option>
<option value="3">Red</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@NonNullByDefault
public class EcowattApiResponseTest {

private static final DecimalType STATE_ZERO = new DecimalType(0);
private static final DecimalType STATE_ONE = new DecimalType(1);
private static final DecimalType STATE_TWO = new DecimalType(2);
private static final DecimalType STATE_THREE = new DecimalType(3);
Expand Down Expand Up @@ -104,6 +105,10 @@ public void getHourSignalStateWithSameOffset() {
State expectedState;
for (int h = 0; h < 24; h++) {
switch (h) {
case 2:
case 3:
expectedState = STATE_ZERO;
break;
case 7:
case 11:
case 19:
Expand Down Expand Up @@ -155,6 +160,10 @@ public void getHourSignalStateWithOtherOffset() {
case 2:
expectedState = UnDefType.UNDEF;
break;
case 5:
case 6:
expectedState = STATE_ZERO;
break;
case 10:
case 14:
case 22:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"signals":[{"GenerationFichier":"2022-09-18T22:00:00+02:00","jour":"2022-09-22T00:00:00+02:00","dvalue":1,"message":"Notre consommation est raisonnable.","values":[{"pas":0,"hvalue":1},{"pas":1,"hvalue":1},{"pas":2,"hvalue":1},{"pas":3,"hvalue":1},{"pas":4,"hvalue":1},{"pas":5,"hvalue":1},{"pas":6,"hvalue":1},{"pas":7,"hvalue":1},{"pas":8,"hvalue":1},{"pas":9,"hvalue":1},{"pas":10,"hvalue":1},{"pas":11,"hvalue":1},{"pas":12,"hvalue":1},{"pas":13,"hvalue":1},{"pas":14,"hvalue":1},{"pas":15,"hvalue":1},{"pas":16,"hvalue":1},{"pas":17,"hvalue":1},{"pas":18,"hvalue":1},{"pas":19,"hvalue":1},{"pas":20,"hvalue":1},{"pas":21,"hvalue":1},{"pas":22,"hvalue":1}]},
{"GenerationFichier":"2022-09-18T22:00:00+02:00","jour":"2022-09-20T00:00:00+02:00","dvalue":2,"message":"Notre consommation est raisonnable.","values":[{"pas":0,"hvalue":1},{"pas":1,"hvalue":1},{"pas":2,"hvalue":1},{"pas":3,"hvalue":1},{"pas":4,"hvalue":1},{"pas":5,"hvalue":1},{"pas":6,"hvalue":1},{"pas":7,"hvalue":1},{"pas":8,"hvalue":1},{"pas":9,"hvalue":1},{"pas":10,"hvalue":1},{"pas":11,"hvalue":1},{"pas":12,"hvalue":1},{"pas":13,"hvalue":1},{"pas":14,"hvalue":1},{"pas":15,"hvalue":1},{"pas":16,"hvalue":1},{"pas":17,"hvalue":1},{"pas":18,"hvalue":1},{"pas":19,"hvalue":1},{"pas":20,"hvalue":2},{"pas":21,"hvalue":1},{"pas":22,"hvalue":1},{"pas":23,"hvalue":1}]},
{"GenerationFichier":"2022-09-18T22:00:00+02:00","jour":"2022-09-21T00:00:00+02:00","dvalue":1,"message":"Notre consommation est raisonnable.","values":[{"pas":0,"hvalue":1},{"pas":1,"hvalue":1},{"pas":2,"hvalue":1},{"pas":3,"hvalue":1},{"pas":4,"hvalue":1},{"pas":5,"hvalue":1},{"pas":6,"hvalue":1},{"pas":7,"hvalue":1},{"pas":8,"hvalue":1},{"pas":9,"hvalue":1},{"pas":10,"hvalue":1},{"pas":11,"hvalue":1},{"pas":12,"hvalue":1},{"pas":13,"hvalue":1},{"pas":14,"hvalue":1},{"pas":15,"hvalue":1},{"pas":16,"hvalue":1},{"pas":17,"hvalue":1},{"pas":18,"hvalue":1},{"pas":19,"hvalue":1},{"pas":20,"hvalue":1},{"pas":21,"hvalue":1},{"pas":22,"hvalue":1},{"pas":23,"hvalue":1}]},
{"GenerationFichier":"2022-09-18T22:00:00+02:00","jour":"2022-09-19T00:00:00+02:00","dvalue":3,"message":"Notre consommation est raisonnable.","values":[{"pas":0,"hvalue":1},{"pas":1,"hvalue":1},{"pas":2,"hvalue":1},{"pas":3,"hvalue":1},{"pas":4,"hvalue":1},{"pas":5,"hvalue":1},{"pas":6,"hvalue":1},{"pas":7,"hvalue":2},{"pas":8,"hvalue":3},{"pas":9,"hvalue":3},{"pas":10,"hvalue":3},{"pas":11,"hvalue":2},{"pas":12,"hvalue":1},{"pas":13,"hvalue":1},{"pas":14,"hvalue":1},{"pas":15,"hvalue":1},{"pas":16,"hvalue":1},{"pas":17,"hvalue":1},{"pas":18,"hvalue":1},{"pas":19,"hvalue":2},{"pas":20,"hvalue":3},{"pas":21,"hvalue":2},{"pas":22,"hvalue":1},{"pas":23,"hvalue":1}]}]}
{"GenerationFichier":"2022-09-18T22:00:00+02:00","jour":"2022-09-19T00:00:00+02:00","dvalue":3,"message":"Notre consommation est raisonnable.","values":[{"pas":0,"hvalue":1},{"pas":1,"hvalue":1},{"pas":2,"hvalue":0},{"pas":3,"hvalue":0},{"pas":4,"hvalue":1},{"pas":5,"hvalue":1},{"pas":6,"hvalue":1},{"pas":7,"hvalue":2},{"pas":8,"hvalue":3},{"pas":9,"hvalue":3},{"pas":10,"hvalue":3},{"pas":11,"hvalue":2},{"pas":12,"hvalue":1},{"pas":13,"hvalue":1},{"pas":14,"hvalue":1},{"pas":15,"hvalue":1},{"pas":16,"hvalue":1},{"pas":17,"hvalue":1},{"pas":18,"hvalue":1},{"pas":19,"hvalue":2},{"pas":20,"hvalue":3},{"pas":21,"hvalue":2},{"pas":22,"hvalue":1},{"pas":23,"hvalue":1}]}]}
Loading

0 comments on commit c0dd8a9

Please sign in to comment.