Skip to content

Commit

Permalink
Merge pull request #13 from HerzScheisse/feature/surepetcare_binding
Browse files Browse the repository at this point in the history
Use Thing property constants and cleanup for removed channels
  • Loading branch information
renescherer authored Oct 28, 2019
2 parents bd7d5fe + b2dd94e commit 6413145
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 200 deletions.
4 changes: 2 additions & 2 deletions bundles/org.openhab.binding.surepetcare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Channel names in **bold** are read/write, everything else is read-only
| **location** | Text | The current location of the pet (0=unknown, 1=inside, 2=outside) |
| locationChanged | DateTime | The time when the location was last changed |
| locationChangedThrough | Text | The device name or username where the pet left/entered the house |
| weight | Number | The pet's weight |
| weight | Number:Mass | The pet's weight (in kilogram) |
| dateOfBirth | DateTime | The pet's date of birth |
| feederDevice | Text | The device from which the pet last ate |
| feederLastChange | Number:Mass | The last eaten change in gram (big bowl) |
Expand Down Expand Up @@ -270,7 +270,7 @@ String UR_1e_TagIdentifier "Pet Tag Identifier [%s]" (dgP
String UR_1e_Location "Pet Location [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:location"}
DateTime UR_1e_LocationChanged "Pet Loc. Updated [%1$ta. %1$tH:%1$tM]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChanged"}
String UR_1e_LocationThrough "Pet Entered / Left through [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChangedThrough"}
Number UR_1e_Weight "Pet Weight [%.1f kg]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"}
Number:Mass UR_1e_Weight "Pet Weight [%.1f %unit%]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"}
DateTime UR_1e_DateOfBirth "Pet Date of Birth [%1$td.%1$tm.%1$tY]" (dgPet) {channel="surepetcare:pet:bridge1:12345:dateOfBirth"}
// Pet Feeder Data
String UR_1e_Device "Device Name [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:feederDevice"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ String UR_1e_TagIdentifier "Pet Tag Identifier [%s]" (dgP
String UR_1e_Location "Pet Location [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:location"}
DateTime UR_1e_LocationChanged "Pet Loc. Updated [%1$ta. %1$tH:%1$tM]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChanged"}
String UR_1e_LocationThrough "Pet Entered / Left through [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChangedThrough"}
Number UR_1e_Weight "Pet Weight [%.1f kg]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"}
Number:Mass UR_1e_Weight "Pet Weight [%.1f %unit%]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"}
DateTime UR_1e_DateOfBirth "Pet Date of Birth [%1$td.%1$tm.%1$tY]" (dgPet) {channel="surepetcare:pet:bridge1:12345:dateOfBirth"}
// Pet Feeder Data
String UR_1e_Device "Device Name [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:feederDevice"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class SurePetcareAPIHelper {
private static final String API_URL = "https://app.api.surehub.io/api";
private static final String TOPOLOGY_URL = API_URL + "/me/start";
private static final String PET_BASE_URL = API_URL + "/pet";
private static final String PET_STATUS_URL = API_URL + "/pet/?with[]=status";
private static final String PET_STATUS_URL = API_URL + "/pet/?with[]=status&with[]=photo";
private static final String DEVICE_BASE_URL = API_URL + "/device";
private static final String LOGIN_URL = API_URL + "/auth/login";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,13 @@ public class SurePetcareConstants {
public static final String HOUSEHOLD_CHANNEL_ID = "id";
public static final String HOUSEHOLD_CHANNEL_NAME = "name";
public static final String HOUSEHOLD_CHANNEL_TIMEZONE_ID = "timezoneId";
public static final String HOUSEHOLD_CHANNEL_CREATED_AT = "createdAt";
public static final String HOUSEHOLD_CHANNEL_UPDATED_AT = "updatedAt";
public static final String HOUSEHOLD_CHANNEL_USER_NAME = "userName";

// Device Channel Names
public static final String DEVICE_CHANNEL_ID = "id";
public static final String DEVICE_CHANNEL_NAME = "name";
public static final String DEVICE_CHANNEL_PRODUCT = "product";
public static final String DEVICE_CHANNEL_LED_MODE = "ledMode";
public static final String DEVICE_CHANNEL_PAIRING_MODE = "pairingMode";
public static final String DEVICE_CHANNEL_HARDWARE_VERSION = "hardwareVersion";
public static final String DEVICE_CHANNEL_FIRMWARE_VERSION = "firmwareVersion";
public static final String DEVICE_CHANNEL_ONLINE = "online";
public static final String DEVICE_CHANNEL_CURFEW_BASE = "curfew";
public static final String DEVICE_CHANNEL_CURFEW_ENABLED = DEVICE_CHANNEL_CURFEW_BASE + "Enabled";
Expand All @@ -84,11 +79,6 @@ public class SurePetcareConstants {
public static final String DEVICE_CHANNEL_LOW_BATTERY = "lowBattery";
public static final String DEVICE_CHANNEL_DEVICE_RSSI = "deviceRSSI";
public static final String DEVICE_CHANNEL_HUB_RSSI = "hubRSSI";
public static final String DEVICE_CHANNEL_CREATED_AT = "createdAt";
public static final String DEVICE_CHANNEL_UPDATED_AT = "updatedAt";
public static final String DEVICE_CHANNEL_PAIRING_AT = "pairingAt";
public static final String DEVICE_CHANNEL_SERIAL_NUMBER = "serialNumber";
public static final String DEVICE_CHANNEL_MAC_ADDRESS = "macAddress";
public static final String DEVICE_CHANNEL_BOWLS_FOOD = "bowlsFood";
public static final String DEVICE_CHANNEL_BOWLS_TARGET = "bowlsTarget";
public static final String DEVICE_CHANNEL_BOWLS_FOOD_LEFT = "bowlsFoodLeft";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.surepetcare.internal.data;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -69,14 +67,6 @@ public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

public ZonedDateTime getCreatedAtAsZonedDateTime() {
return createdAt.toInstant().atZone(ZoneId.systemDefault());
}

public ZonedDateTime getUpdatedAtAsZonedDateTime() {
return updatedAt.toInstant().atZone(ZoneId.systemDefault());
}

public Map<String, String> getThingProperties() {
Map<String, String> properties = new HashMap<String, String>();
properties.put("id", id.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
*/
package org.openhab.binding.surepetcare.internal.data;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.thing.Thing;

/**
* The {@link SurePetcareDevice} is the Java class used
Expand Down Expand Up @@ -163,10 +162,10 @@ public void setStatus(SurePetcareDeviceStatus status) {
properties.put("householdId", householdId.toString());
properties.put("productType", productId.toString());
properties.put("productName", ProductType.findByTypeId(productId).getName());
properties.put("macAddress", macAddress);
properties.put("serialNumber", serialNumber);
properties.put("hardwareVersion", status.getVersion().device.hardware.toString());
properties.put("firmwareVersion", status.getVersion().device.firmware.toString());
properties.put(Thing.PROPERTY_MAC_ADDRESS, macAddress);
properties.put(Thing.PROPERTY_SERIAL_NUMBER, serialNumber);
properties.put(Thing.PROPERTY_HARDWARE_VERSION, status.getVersion().device.hardware);
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, status.getVersion().device.firmware);
if (pairingAt != null) {
properties.put("pairingAt", pairingAt.toString());
}
Expand All @@ -179,10 +178,6 @@ public String toString() {
+ "]";
}

public @NonNull ZonedDateTime getPairingAtAsZonedDateTime() {
return pairingAt.toInstant().atZone(ZoneId.systemDefault());
}

public SurePetcareDevice assign(SurePetcareDevice newdev) {
super.assign(newdev);
this.parentDeviceId = newdev.parentDeviceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.surepetcare.internal.data;

import java.math.BigDecimal;

import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -31,8 +29,8 @@ public class Locking {

public class Version {
public class Device {
public BigDecimal hardware;
public BigDecimal firmware;
public String hardware;
public String firmware;
}

public Device device = new Device();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.openhab.binding.surepetcare.internal.SurePetcareConstants.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.library.types.DateTimeType;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Thing;
Expand Down Expand Up @@ -47,8 +46,6 @@ protected void updateThing() {
updateState(HOUSEHOLD_CHANNEL_ID, new DecimalType(household.getId()));
updateState(HOUSEHOLD_CHANNEL_NAME, new StringType(household.getName()));
updateState(HOUSEHOLD_CHANNEL_TIMEZONE_ID, new DecimalType(household.getTimezoneId()));
updateState(HOUSEHOLD_CHANNEL_CREATED_AT, new DateTimeType(household.getCreatedAtAsZonedDateTime()));
updateState(HOUSEHOLD_CHANNEL_UPDATED_AT, new DateTimeType(household.getUpdatedAtAsZonedDateTime()));
} else {
logger.debug("Trying to update unknown household: {}", thing.getUID().getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.eclipse.smarthome.core.types.UnDefType;
import org.eclipse.smarthome.io.net.http.HttpUtil;
import org.openhab.binding.surepetcare.internal.SurePetcareAPIHelper;
import org.openhab.binding.surepetcare.internal.SurePetcareApiException;
Expand Down Expand Up @@ -108,24 +109,17 @@ protected void updateThing() {
if (pet != null) {
logger.debug("Updating all thing channels for pet : {}", pet);
updateState(PET_CHANNEL_ID, new DecimalType(pet.getId()));
if (pet.getName() != null) {
updateState(PET_CHANNEL_NAME, new StringType(pet.getName()));
}
if (pet.getComments() != null) {
updateState(PET_CHANNEL_COMMENT, new StringType(pet.getComments()));
}
if (pet.getGenderId() != null) {
updateState(PET_CHANNEL_GENDER, new StringType(pet.getGenderId().toString()));
}
if (pet.getBreedId() != null) {
updateState(PET_CHANNEL_BREED, new StringType(pet.getBreedId().toString()));
}
if (pet.getSpeciesId() != null) {
updateState(PET_CHANNEL_SPECIES, new StringType(pet.getSpeciesId().toString()));
}
if (pet.getPhoto() != null) {
updateState(PET_CHANNEL_PHOTO, getPetPhotoImage(pet.getPhoto().getLocation()));
}
updateState(PET_CHANNEL_NAME, pet.getName() == null ? UnDefType.UNDEF : new StringType(pet.getName()));
updateState(PET_CHANNEL_COMMENT,
pet.getComments() == null ? UnDefType.UNDEF : new StringType(pet.getComments()));
updateState(PET_CHANNEL_GENDER,
pet.getGenderId() == null ? UnDefType.UNDEF : new StringType(pet.getGenderId().toString()));
updateState(PET_CHANNEL_BREED,
pet.getBreedId() == null ? UnDefType.UNDEF : new StringType(pet.getBreedId().toString()));
updateState(PET_CHANNEL_SPECIES,
pet.getSpeciesId() == null ? UnDefType.UNDEF : new StringType(pet.getSpeciesId().toString()));
updateState(PET_CHANNEL_PHOTO,
pet.getPhoto() == null ? UnDefType.UNDEF : getPetPhotoImage(pet.getPhoto().getLocation()));
SurePetcarePetActivity loc = pet.getPetStatus().getActivity();
if (loc != null) {
updateState(PET_CHANNEL_LOCATION, new StringType(loc.getWhere().toString()));
Expand All @@ -134,12 +128,9 @@ protected void updateThing() {
}
}
ZonedDateTime dob = pet.getDateOfBirthAsZonedDateTime();
if (dob != null) {
updateState(PET_CHANNEL_DATE_OF_BIRTH, new DateTimeType(dob));
}
if (pet.getWeight() != null) {
updateState(PET_CHANNEL_WEIGHT, new DecimalType(pet.getWeight()));
}
updateState(PET_CHANNEL_DATE_OF_BIRTH, dob == null ? UnDefType.UNDEF : new DateTimeType(dob));
updateState(PET_CHANNEL_WEIGHT, pet.getWeight() == null ? UnDefType.UNDEF
: new QuantityType<Mass>(pet.getWeight(), SIUnits.KILOGRAM));
if (pet.getTagId() != null) {
SurePetcareTag tag = petcareAPI.getTag(pet.getTagId().toString());
if (tag != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ channel-type.surepetcare.pairingModeType.description = The current pairing mode
channel-type.surepetcare.pairingModeType.state.option.0 = Normal Mode
channel-type.surepetcare.pairingModeType.state.option.1 = Pairing Mode

channel-type.surepetcare.hardwareVersionType.label = Hardware Version
channel-type.surepetcare.hardwareVersionType.description = The version of the hardware.

channel-type.surepetcare.firmwareVersionType.label = Firmware Version
channel-type.surepetcare.firmwareVersionType.description = The version of the firmware.

channel-type.surepetcare.onlineType.label = Online State
channel-type.surepetcare.onlineType.description = Indicator if device is online or offline.

Expand All @@ -174,21 +168,6 @@ channel-type.surepetcare.curfewLockTimeType.description = The time when the curf
channel-type.surepetcare.curfewUnlockTimeType.label = Curfew Unlock Time
channel-type.surepetcare.curfewUnlockTimeType.description = The time when the curfew finishes.

channel-type.surepetcare.createdAtType.label = Created At
channel-type.surepetcare.createdAtType.description = The Time when the device was created.

channel-type.surepetcare.updatedAtType.label = Updated At
channel-type.surepetcare.updatedAtType.description = The Time when the device was updated.

channel-type.surepetcare.pairingAtType.label = Pairing At
channel-type.surepetcare.pairingAtType.description = The Time when the device was paired.

channel-type.surepetcare.serialNumberType.label = Serial Number
channel-type.surepetcare.serialNumberType.description = The serial number of the device.

channel-type.surepetcare.macAddressType.label = MAC Address
channel-type.surepetcare.macAddressType.description = The MAC address of the device.

channel-type.surepetcare.dateOfBirthType.label = Pet Birthday
channel-type.surepetcare.dateOfBirthType.description = The pet birthday.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ channel-type.surepetcare.pairingModeType.description = Zeigt den Paarungs Modus
channel-type.surepetcare.pairingModeType.state.option.0 = Normaler Modus
channel-type.surepetcare.pairingModeType.state.option.1 = Paarungsmodus

channel-type.surepetcare.hardwareVersionType.label = Hardware Version
channel-type.surepetcare.hardwareVersionType.description = Zeigt die Hardware Version des Gerätes an.

channel-type.surepetcare.firmwareVersionType.label = Firmware Version
channel-type.surepetcare.firmwareVersionType.description = Zeigt die Firmware Version des Gerätes an.

channel-type.surepetcare.onlineType.label = Online Status
channel-type.surepetcare.onlineType.description = Zeigt den Online Status des Gerätes an.

Expand All @@ -174,21 +168,6 @@ channel-type.surepetcare.curfewLockTimeType.description = Zeigt die Sperrzeit de
channel-type.surepetcare.curfewUnlockTimeType.label = Ausgangssperre Entsperrzeit
channel-type.surepetcare.curfewUnlockTimeType.description = Zeigt die Entsperrzeit der Ausgangssperre an.

channel-type.surepetcare.createdAtType.label = Erstell Datum
channel-type.surepetcare.createdAtType.description = Zeigt das Erstelldatum an.

channel-type.surepetcare.updatedAtType.label = Aktualisierungs Datum
channel-type.surepetcare.updatedAtType.description = Zeigt das Aktualisierungsdatum an.

channel-type.surepetcare.pairingAtType.label = Verbindungs Datum
channel-type.surepetcare.pairingAtType.description = Zeigt das Verbindungsdatum an.

channel-type.surepetcare.serialNumberType.label = Serien Nummer
channel-type.surepetcare.serialNumberType.description = Zeigt die Seriennummer des Gerätes an.

channel-type.surepetcare.macAddressType.label = MAC Adresse
channel-type.surepetcare.macAddressType.description = Zeigt die MAC Adresse des Gerätes an.

channel-type.surepetcare.dateOfBirthType.label = Geburtstag
channel-type.surepetcare.dateOfBirthType.description = Zeigt den Geburtstag des Haus an.

Expand Down
Loading

0 comments on commit 6413145

Please sign in to comment.