Skip to content

Commit

Permalink
Support for Shelly BLU Gateway Gen3
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Michels <[email protected]>
  • Loading branch information
markus7017 committed Jan 24, 2025
1 parent de951f5 commit 6602233
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class ShellyThingCreator {
public static final String SHELLYDT_BLUMOTION = "SBMO";
public static final String SHELLYDT_BLUHT = "SBHT";
public static final String SHELLYDT_BLUGW = "SNGW-BT01";
public static final String SHELLYDT_BLUGWG3 = "S3GW-1DBT001";

// Thing names
public static final String THING_TYPE_SHELLY1_STR = "shelly1";
Expand Down Expand Up @@ -226,6 +227,7 @@ public class ShellyThingCreator {
public static final String THING_TYPE_SHELLYBLUMOTION_STR = THING_TYPE_SHELLYBLU_PREFIX + "motion";
public static final String THING_TYPE_SHELLYBLUHT_STR = THING_TYPE_SHELLYBLU_PREFIX + "ht";
public static final String THING_TYPE_SHELLYBLUGW_STR = THING_TYPE_SHELLYBLU_PREFIX + "gw";
public static final String THING_TYPE_SHELLYBLUGWG3_STR = THING_TYPE_SHELLYBLU_PREFIX + "gwg3";

// Password protected or unknown device
public static final String THING_TYPE_SHELLYPROTECTED_STR = "shellydevice";
Expand Down Expand Up @@ -454,6 +456,7 @@ public class ShellyThingCreator {
THING_TYPE_MAPPING.put(SHELLYDT_BLUMOTION, THING_TYPE_SHELLYBLUMOTION_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUHT, THING_TYPE_SHELLYBLUHT_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUGW, THING_TYPE_SHELLYBLUGW_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUGWG3, THING_TYPE_SHELLYBLUGW_STR);

// Wall displays
THING_TYPE_MAPPING.put(SHELLYDT_PLUSWALLDISPLAY, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR);
Expand Down Expand Up @@ -527,6 +530,13 @@ public class ShellyThingCreator {
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3_STR, THING_TYPE_SHELLYPRO3_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO4PM_STR, THING_TYPE_SHELLYPRO4PM_STR);

THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUBUTTON_STR, THING_TYPE_SHELLYBLUBUTTON_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUDW_STR, THING_TYPE_SHELLYBLUDW_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUMOTION_STR, THING_TYPE_SHELLYBLUMOTION_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUHT_STR, THING_TYPE_SHELLYBLUHT_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUGW_STR, THING_TYPE_SHELLYBLUGW_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUGWG3_STR, THING_TYPE_SHELLYBLUGW_STR);

THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROTECTED_STR, THING_TYPE_SHELLYPROTECTED_STR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private void addAttribute(Map<String, String> properties, ShellyManagerInterface
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
break;
default:
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
value = getTimestamp(dateTimeState);
}
} else {
value = state.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,17 @@ public static DateTimeType getTimestamp(String zone, long timestamp) {
ZoneId zoneId = !zone.isEmpty() ? ZoneId.of(zone) : ZoneId.systemDefault();
ZonedDateTime zdt = LocalDateTime.now().atZone(zoneId);
int delta = zdt.getOffset().getTotalSeconds();
return new DateTimeType(Instant.ofEpochSecond(timestamp - delta));
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp - delta), zoneId));
} catch (DateTimeException e) {
// Unable to convert device's timezone, use system one
return getTimestamp();
}
}

public static String getTimestamp(DateTimeType dt) {
return dt.getZonedDateTime().toString().replace('T', ' ').replace('-', '/');
}

public static String convertTimestamp(long ts) {
if (ts == 0) {
return "";
Expand Down

0 comments on commit 6602233

Please sign in to comment.