Skip to content

Commit

Permalink
Adding today and tomorrow event to file.
Browse files Browse the repository at this point in the history
Signed-off-by: gael@lhopital.org <gael@lhopital.org>
  • Loading branch information
clinique committed Apr 23, 2024
1 parent ecb67cc commit d2247a4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
26 changes: 12 additions & 14 deletions bundles/org.openhab.binding.ephemeris/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ The file has to use the syntax described here : https://www.openhab.org/docs/con
| name | text | Name of the dayset used | N/A | yes | no |



## Channels

_Here you should provide information about available channel types, what their meaning is and how they can be used._
Expand All @@ -53,29 +52,28 @@ _Note that it is planned to generate some part of this based on the XML files wi

## Full Example

_Provide a full usage example based on textual configuration files._
_*.things, *.items examples are mandatory as textual configuration is well used by many users._
_*.sitemap examples are optional._

### Thing Configuration

```java
Example thing configuration goes here.
Thing ephemeris:holiday:local "Holidays"
Thing ephemeris:weekend:local "Week-end"
Thing ephemeris:file:events "Event" [fileName="events.xml"]
```

### Item Configuration

```java
Example item configuration goes here.
```
String ToD_Event_Current "Event Today" <calendar> (gEvents) ["Event"] {channel="ephemeris:file:events:title-today"}
String ToD_Event_Next "Event Next" <calendar> (gEvents) ["Event"] {channel="ephemeris:file:events:next-title"}
Number:Time ToD_Event_Next_Left "Event In" <calendar> (gEvents) ["Measurement","Duration"] {channel="ephemeris:file:events:days-remaining", unit="day"}

### Sitemap Configuration
Switch ToD_Week_End_Current "Week-End" <calendar> (gWeekEnd) ["Event"] {channel="ephemeris:weekend:local:today"}
Switch ToD_Week_End_Tomorrow "Week-End Tomorrow" <calendar> (gWeekEnd) ["Event"] {channel="ephemeris:weekend:local:tomorrow"}

```perl
Optional Sitemap configuration goes here.
Remove this section, if not needed.
```
String ToD_Holiday_Current "Holiday Today" <calendar> (gHoliday) ["Event"] {channel="ephemeris:holiday:local:title-today"}
String ToD_Holiday_Next "Holiday Next" <calendar> (gHoliday) ["Event"] {channel="ephemeris:holiday:local:next-title"}
Number:Time ToD_Holiday_Next_Left "Holiday In" <calendar> (gHoliday) ["Measurement","Duration"] {channel="ephemeris:holiday:local:days-remaining", unit="day"}

## Any custom content here!
```

_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class EphemerisBindingConstants {
public static final String CHANNEL_TOMORROW = "tomorrow";
public static final String CHANNEL_HOLIDAY_TODAY = "holiday-today";
public static final String CHANNEL_HOLIDAY_TOMORROW = "holiday-tomorrow";
public static final String CHANNEL_EVENT_TODAY = "event-today";
public static final String CHANNEL_EVENT_TOMORROW = "event-tomorrow";

// Folder for xml storage eg: /etc/openhab/misc/ephemeris
public static final String BINDING_DATA_PATH = "%s%smisc%s%s".formatted(OpenHAB.getConfigFolder(), File.separator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.ephemeris.internal.handler;

import static org.openhab.binding.ephemeris.internal.EphemerisBindingConstants.BINDING_DATA_PATH;
import static org.openhab.binding.ephemeris.internal.EphemerisBindingConstants.*;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -24,6 +24,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.ephemeris.internal.configuration.FileConfiguration;
import org.openhab.core.ephemeris.EphemerisManager;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
Expand All @@ -49,10 +50,18 @@ public void initialize() {
}

@Override
protected @Nullable String internalUpdate(ZonedDateTime now) {
protected @Nullable String internalUpdate(ZonedDateTime today) {
if (definitionFile.isPresent()) {
File file = definitionFile.get();
return file.exists() ? super.internalUpdate(now) : "Missing file: %s".formatted(file.getAbsolutePath());
if (file.exists()) {
String event = getEvent(today);
updateState(CHANNEL_EVENT_TODAY, OnOffType.from(event != null));

event = getEvent(today.plusDays(1));
updateState(CHANNEL_EVENT_TOMORROW, OnOffType.from(event != null));
return super.internalUpdate(today);
}
return "Missing file: %s".formatted(file.getAbsolutePath());
}
throw new IllegalArgumentException("Initialization problem, please file a bug.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ thing-type.ephemeris.dayset.label = Dayset
thing-type.ephemeris.dayset.description = Events based on a given dayset
thing-type.ephemeris.file.label = Ephemeris File
thing-type.ephemeris.file.description = Events defined in a Jollyday file
thing-type.ephemeris.file.channel.event-today.label = Event Today
thing-type.ephemeris.file.channel.event-today.description = Set to ON if an event exists today
thing-type.ephemeris.file.channel.event-tomorrow.label = Event Tomorrow
thing-type.ephemeris.file.channel.event-tomorrow.description = Set to ON if an event exists tomorrow
thing-type.ephemeris.holiday.label = Ephemeris Holidays
thing-type.ephemeris.holiday.description = Holidays based on system default Ephemeris configuration
thing-type.ephemeris.holiday.channel.holiday-today.label = Holiday Today
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

<channels>
<channel id="title-today" typeId="event_current_title"/>
<channel id="event-today" typeId="in-dayset">
<label>Event Today</label>
<description>Set to ON if an event exists today</description>
</channel>
<channel id="event-tomorrow" typeId="in-dayset">
<label>Event Tomorrow</label>
<description>Set to ON if an event exists tomorrow</description>
</channel>
<channel id="next-title" typeId="event_next_title"/>
<channel id="next-start" typeId="event_next_start"/>
<channel id="days-remaining" typeId="remaining_days"/>
Expand Down

0 comments on commit d2247a4

Please sign in to comment.