Skip to content

Commit

Permalink
Capabilities enhancement and @jlaur code review integration.
Browse files Browse the repository at this point in the history
Signed-off-by: clinique <gael@lhopital.org>
  • Loading branch information
clinique committed Feb 26, 2022
1 parent df04e05 commit 96563c0
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 433 deletions.
36 changes: 17 additions & 19 deletions bundles/org.openhab.binding.netatmo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ The binding has the following configuration options:
Create a `<openHAB-conf>/services/netatmo.cfg` file and use the above options like this:

```
binding.netatmo:clientId=ezezsdfdssfhdreytr
binding.netatmo:clientSecret=dshfdkfdfkshdkj
binding.netatmo:username=mail@mail.com
binding.netatmo:password=dssdsdsd
binding.netatmo:clientId=<CLIENT_ID>
binding.netatmo:clientSecret=<CLIENT_SECRET>
binding.netatmo:username=your.mail@address.something
binding.netatmo:password=<PASSWORD>
```


Expand Down Expand Up @@ -130,11 +130,11 @@ Based on a standard update period of 10mn by Netatmo systems - it will auto adap
| temperature | min-time | DateTime | Timestamp of today's minimum temperature |
| temperature | max-time | DateTime | Timestamp of today's maximum temperature |
| temperature | trend | String | Temperature evolution trend over time |
| airquality | co2 | Number:Dimensionless | Air quality |
| airquality | co2 | Number:Dimensionless | CO2 level in ppm |
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |


All these channels are read only.
Expand All @@ -161,7 +161,7 @@ All these channels are read only.
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |
| battery | value | Number | Battery level |
| battery | low-battery | Switch | Low battery |

Expand Down Expand Up @@ -191,7 +191,7 @@ All these channels are read only.
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |
| battery | value | Number | Battery level |
| battery | low-battery | Switch | Low battery |

Expand All @@ -211,7 +211,7 @@ All these channels are read only.
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |
| battery | value | Number | Battery level |
| battery | low-battery | Switch | Low battery |

Expand All @@ -235,7 +235,7 @@ All these channels are read only.
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |
| battery | value | Number | Battery level |
| battery | low-battery | Switch | Low battery |

Expand Down Expand Up @@ -269,7 +269,7 @@ All these channels are read only.
| timestamp | last-seen | DateTime | Timestamp when module was last seen |
| timestamp | measures | DateTime | Timestamp of current measures |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |


(*) Health index values :
Expand All @@ -290,7 +290,7 @@ All these channels are read only.
| Channel Group | Channel Id | Item Type | Description |
|---------------------|--------------------|----------------------|--------------------------------------------------|
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |

All these channels are read only.

Expand All @@ -303,14 +303,14 @@ All these channels are read only.
|---------------------|--------------------|------------------------------------------------------------|
| temperature | Number:Temperature | Current temperature |
| setpoint | Number:Temperature | Thermostat temperature setpoint |
| setpoint-mode | String | Chosen setpoint_mode (program, away, hg, manual, off, max) |
| setpoint-mode | String | Chosen setpoint mode (program, away, hg, manual, off, max) |
| ThermRelayCmd | Switch | Indicates whether the furnace is heating or not |
| anticipating | Switch | Indicates is anticipating the schedule |
| timestamp | DateTime | Timestamp when data was measured |
| setpoint-end | DateTime | Thermostat goes back to schedule after that timestamp |
| last-message | DateTime | Last message emitted by the module |
| signal | strength | Number | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Signal strength in dB |
| signal | value | Number:Power | Signal strength in dBm |
| battery | value | Number | Battery level |
| battery | low-battery | Switch | Low battery |
| battery | status | String | Description of the battery status (*) |
Expand Down Expand Up @@ -400,7 +400,7 @@ Warnings:
| live | picture-url | String | Read-only | Url of the live snapshot for this camera |
| live | stream-url (*) | String | Read-only | Url of the live stream for this camera |
| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Read-only | Signal strength in dB |
| signal | value | Number:Power | Read-only | Signal strength in dBm |

(*) This channel is configurable : low, poor, high.

Expand All @@ -419,7 +419,7 @@ Warnings:
| live | picture-url | String | Read-only | Url of the live snapshot for this camera |
| live | stream-url (*) | String | Read-only | Url of the live stream for this camera |
| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Read-only | Signal strength in dB |
| signal | value | Number:Power | Read-only | Signal strength in dBm |
| presence | auto-mode | Switch | Read-write | When set the floodlight gets switched to auto instead of off |
| presence | floodlight | Switch | Read-write | Switch for the floodlight |

Expand Down Expand Up @@ -598,9 +598,7 @@ sitemap netatmo label="Netatmo" {
# Sample data

If you want to evaluate this binding but have not got a Netatmo station yourself
yet, you can add the Netatmo office in Paris to your account:

http://www.netatmo.com/en-US/addguest/index/TIQ3797dtfOmgpqUcct3/70:ee:50:00:02:20
yet, you can search on the web for a publicly shared weather station.


# Icons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ public class NetatmoBindingConstants {
public static final String CHANNEL_SETPOINT_DURATION = "setpoint-duration";

// Presence outdoor camera specific channels
public static final String CHANNEL_CAMERA_FLOODLIGHT_AUTO_MODE = "auto-mode";
public static final String CHANNEL_CAMERA_FLOODLIGHT = "floodlight";
public static final String CHANNEL_FLOODLIGHT_AUTO_MODE = "auto-mode";
public static final String CHANNEL_FLOODLIGHT = "floodlight";
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void setRoomThermpoint(
}

try {
roomHandler.thingActionCallSetRoomThermTemp(targetTemp != null ? targetTemp : 0,
roomHandler.setRoomThermTemp(targetTemp != null ? targetTemp : 0,
targetEndTime != null ? targetEndTime : 0L, SetpointMode.valueOf(targetMode));
} catch (IllegalArgumentException e) {
logger.debug("Ignoring setRoomThermpoint command due to illegal argument exception: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public AircareApi(ApiBridge apiClient) {
}

/**
*
* Returns data from Healthy Home Coach Station (measures and device specific data).
*
* @param deviceId Id of the device you want to retrieve information of (optional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.eclipse.jetty.http.HttpStatus.Code;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.Scope;
import org.openhab.binding.netatmo.internal.config.NetatmoBindingConfiguration;
import org.openhab.binding.netatmo.internal.config.NetatmoBindingConfiguration.NACredentials;
import org.openhab.binding.netatmo.internal.config.NetatmoBindingConfiguration.Credentials;
import org.openhab.binding.netatmo.internal.deserialization.NADeserializer;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.common.ThreadPoolManager;
Expand Down Expand Up @@ -95,8 +95,8 @@ public void openConnection(@Nullable Map<String, Object> config) {
if (config != null) {
configuration.update(config);
}
logger.debug("Updated binding configuration to {}", configuration);
NACredentials credentials = configuration.getCredentials();
Credentials credentials = configuration.getCredentials();
logger.debug("Updated binding configuration to {}", credentials);
if (credentials != null) {
connectApi.authenticate(credentials);
notifyListeners();
Expand Down Expand Up @@ -182,6 +182,9 @@ synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz, @Nulla
throw exception;
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new NetatmoException(e, "Exception while calling %s", uri.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.Scope;
import org.openhab.binding.netatmo.internal.api.dto.NAAccessTokenResponse;
import org.openhab.binding.netatmo.internal.config.NetatmoBindingConfiguration.NACredentials;
import org.openhab.binding.netatmo.internal.config.NetatmoBindingConfiguration.Credentials;
import org.openhab.core.common.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -54,7 +54,7 @@ class AuthenticationApi extends RestManager {
super(bridge, FeatureArea.NONE);
}

void authenticate(NACredentials credentials) throws NetatmoException {
void authenticate(Credentials credentials) throws NetatmoException {
requestToken(credentials.clientId, credentials.clientSecret,
Map.of(SCOPE, FeatureArea.ALL_SCOPES, PASSWORD, credentials.password, USERNAME, credentials.username));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

@NonNullByDefault
public class EnergyApi extends RestManager {

public EnergyApi(ApiBridge apiClient) {
super(apiClient, FeatureArea.ENERGY);
}
Expand Down Expand Up @@ -88,7 +87,7 @@ public void setRoomThermpoint(String homeId, String roomId, SetpointMode mode, l
if (mode == SetpointMode.MANUAL || mode == SetpointMode.MAX) {
uriBuilder.queryParam("endtime", endtime);
if (mode == SetpointMode.MANUAL) {
uriBuilder.queryParam("temp", temp > 30 ? 30 : temp);
uriBuilder.queryParam("temp", temp > THERM_MAX_SETPOINT ? THERM_MAX_SETPOINT : temp);
}
}
post(uriBuilder, ApiResponse.Ok.class, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public SecurityApi(ApiBridge apiClient) {
}

/**
*
* Dissociates a webhook from a user.
*
* @return boolean Success
Expand All @@ -52,7 +51,6 @@ public boolean dropWebhook() throws NetatmoException {
}

/**
*
* Links a callback url to a user.
*
* @param uri Your webhook callback url (required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public enum RefreshPolicy {
public final List<Class<? extends AbstractChannelHelper>> channelHelpers;
public final @Nullable ModuleType bridgeType;
public final @Nullable Class<?> handlerClass;
// TODO : à voir à la fin du refactoring, je pense que les notions de dto par défaut n'auront plus aucun intérêt
// sauf pour weather et aircare
// TODO : evaluate when refactoring toward new api is over if dto is still interesting here
// currently only weather station and aircare are using it
public final @Nullable Class<?> dto;
public final ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, name());
public final RefreshPolicy refreshPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public enum MeasureClass {
@Deprecated
public static final String SUB_PATH_GETCAMERAPICTURE = "getcamerapicture";

// Global variables
public static final int THERM_MAX_SETPOINT = 30;

// Token scopes
public static enum Scope {
@SerializedName("read_station")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
*/
package org.openhab.binding.netatmo.internal.api.dto;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;

/**
* The {@link NAHome} holds home information.
Expand All @@ -30,19 +26,8 @@

@NonNullByDefault
public class NAHome extends NADevice implements NetatmoLocation {
// Common part
private double[] coordinates = {};
private double altitude;
private NAObjectMap<NARoom> rooms = new NAObjectMap<>();

// Energy specific part
// private SetpointMode thermMode = SetpointMode.UNKNOWN;
private @Nullable ZonedDateTime thermModeEndtime;
// private int thermSetpointDefaultDuration;

// Security specific part
public NAObjectMap<NAPerson> persons = new NAObjectMap<>();
// public NAObjectMap<NAWelcome> cameras = new NAObjectMap<>();
private List<NAHomeEvent> events = List.of();

@Override
Expand All @@ -60,39 +45,7 @@ public double[] getCoordinates() {
return coordinates;
}

public NAObjectMap<NARoom> getRooms() {
return rooms;
}

public @Nullable ZonedDateTime getThermModeEndTime() {
return thermModeEndtime;
}

// public int getThermSetpointDefaultDuration() {
// return thermSetpointDefaultDuration;
// }

// public SetpointMode getThermMode() {
// return thermMode;
// }

public NAObjectMap<NAPerson> getPersons() {
return persons;
}

public List<NAPerson> getKnownPersons() {
return persons.values().stream().filter(person -> person.getName() != null).collect(Collectors.toList());
}

public List<NAHomeEvent> getEvents() {
return events;
}

// public NAObjectMap<NAWelcome> getCameras() {
// return cameras;
// }

public void setEvents(List<NAHomeEvent> events) {
this.events = events;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public class HomeStatus extends NAThing {
private @Nullable NAObjectMap<NAHomeStatusPerson> persons;
private @Nullable NAObjectMap<NARoom> rooms;

public @Nullable NAObjectMap<NAHomeStatusModule> getModules() {
return modules;
public NAObjectMap<NAHomeStatusModule> getModules() {
return modules != null ? modules : new NAObjectMap<>();
}

public @Nullable NAObjectMap<NAHomeStatusPerson> getPersons() {
return persons;
public NAObjectMap<NAHomeStatusPerson> getPersons() {
return persons != null ? persons : new NAObjectMap<>();
}

public @Nullable NAObjectMap<NARoom> getRooms() {
return rooms;
public NAObjectMap<NARoom> getRooms() {
return rooms != null ? rooms : new NAObjectMap<>();
}
}

Expand Down
Loading

0 comments on commit 96563c0

Please sign in to comment.