-
-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement geofence-based presence #355
Conversation
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); | ||
|
||
// Define the notification settings. | ||
builder.setSmallIcon(R.drawable.ic_launcher) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually apps use their icon with a background in notifications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! This was lifted from elsewhere. Fixed.
// to decode the Bitmap. | ||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), | ||
R.drawable.ic_launcher)) | ||
.setColor(Color.RED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why red?
R.drawable.ic_launcher)) | ||
.setColor(Color.RED) | ||
.setContentTitle(notificationDetails) | ||
.setContentText("Geofence transition") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
case Geofence.GEOFENCE_TRANSITION_DWELL: | ||
return "GEOFENCE_TRANSITION_DWELL"; | ||
default: | ||
return "Unknown type"+transitionType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this visible to the user? If so please use strings.xml ressources for this.
lat = Float.parseFloat(mSettings.getString(Constants.PREFERENCE_PRESENCE_LAT, "0")); | ||
lng = Float.parseFloat(mSettings.getString(Constants.PREFERENCE_PRESENCE_LNG, "0")); | ||
} catch(NumberFormatException e) { | ||
Log.i(TAG, "Invalid lat/lng"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the user get feedback that lat/lng is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do now:)
<CheckBoxPreference | ||
android:defaultValue="false" | ||
android:key="default_openhab_presence_enable" | ||
android:summary="Enable location-based presence reporting" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
android:inputType="textNoSuggestions" | ||
android:key="default_openhab_presence_item" | ||
android:summary="" | ||
android:title="Presence Item" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
android:inputType="numberDecimal" | ||
android:key="default_openhab_presence_lat" | ||
android:summary="" | ||
android:title="Latitude" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
android:inputType="numberDecimal" | ||
android:key="default_openhab_presence_lng" | ||
android:summary="" | ||
android:title="Longitude" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
android:dependency="default_openhab_presence_enable" | ||
android:key="default_openhab_presence_debug" | ||
android:summary="Enable debug notifications" | ||
android:title="Debugging" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.xml ressources for this.
android:summary="" | ||
android:title="Latitude" /> | ||
<EditTextPreference | ||
android:defaultValue="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could replace ""
with "@string/empty_string"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entire clear what you meant, but I just removed the default.
Hi @jjhuff , thanks for the PR, and thanks @mueller-ma for the initial review. I need to find a large block of time to get through all the android PR's this week. |
Thanks for the review @mueller-ma. I think I fixed everything you flagged. |
@@ -58,6 +58,38 @@ | |||
android:summary="@string/settings_openhab_sslhost_summary" | |||
android:title="@string/settings_openhab_sslhost" /> | |||
</PreferenceCategory> | |||
<PreferenceCategory android:title="Presence"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded string
android:dependency="default_openhab_presence_enable" | ||
android:inputType="numberDecimal" | ||
android:key="default_openhab_presence_lng" | ||
android:summary="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you display the selected value as summary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, done!
@jjhuff I just had a chance to run this. Couple of suggestions. My thoughts for this functionality would be that you select a location from a map (using google map api) and then select and item to switch on when you enter it, off when you exit it. I was not expecting the user to manually enter a single lat/lon or the actual item name. Would it be possible to let the user select a map for the location, and also fetch a list of items (/rest/items) from the users server to select? Even better, supporting multiple geofences -> items would be awesome. |
@digitaldan I think both of those would be great, but I wanted to start somewhere
|
What I would like to see is this not in the preferences menu, but in the main menu where we already have "write nfc tag", so something like "Geo Fences". when selecting this it pops up a window showing your saved geofences , or a button/link to create a new one. For selecting an item, If you are not connected to a server then you would have an empty dropdown menu, but could still type into the field (if we think its an issue) , selecting from the dropdown would populate that item name in the field.
So, I think your point of view here is that this is meant for geofencing your home, but that is only one use case. For example, I have a geofence when I drive into my neighborhood and another one for when I get home. I also have a geo fence for work. Tying this to a single location seems a bit limiting, and not what I would expect from a geo fence feature. Btw, I love this feature! We want to bump our app version to 2.0 soon and this could be a great reason to do so. |
Gotcha. Yup, that solves a lot of problems.
100% agree! However, my main point is that I think that the fences should be defined/stored on the server rather than every single client. Perhaps I have multiple devices, a family, or employees. Proposal 1: Proposal 2:
I suppose you could also have a config file to assign symbolic names to replace the lat,lng,radius values. |
Apologies for the very late reply, I am catching up on PR's today. So i had to think about this, I still would prefer that a user selects a location and radius from a map, then selects an item. I think this would be amazingly simple and be used frequently. I am however trying to also see it from your POV, and so keeping an open mind. For this project, we always have to keep in mind that it's the official Android app for openHAB. This means we need to keep design focused on complimenting the openHAB server and its built in functionality. So I'm generally opposed to requiring users to have to install a new binding unless it would absolutely be necessary . I also believe we can not overload basic OH concepts like items or sitemaps to meet bespoke functionality. That being said, we do have the concept of a Location item. If the user were to select a location item and another item to switch on or off I have a couple questions on how this would work.
My opinion is that this over complicates the feature, but again its' just my opinion.
The android app should work without any special configuration on the server that is specific to the app, i would like to avoid the user having to install a binding unless there was no alternative.
I think we are overloading what an item is, so I don't think we can do that in this app. I'm hoping you are still interested in developing this feature! I think it would be awesome. |
Just an idea: why not having something similar to the voice recognition, that is the Android app updating a location item with the current phone position ? Then the user could use this position in rules and set switch for example when the phone position is around a particular position. With which frequence the app will update the position ? With what impact on phone battery ? |
I think that's the issue, not only would our app now wake up in the background for location changes events, but it also tries to wake up the radio and make REST calls at some frequent interval. I was hoping not to have to deal with possible battery issues with our app. |
I apologize for being MIA -- new job sucked away all of my free time! How are people feeling about where this sits? I see an approval (I missed that earlier). I'm happy to clean up the merge conflicts if there's still overall interest in the feature. I agree that a map would be a logical next step, but I'm also not super keen to draw this out. Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the data stored on client isnt very practical, especially since you dont have a map to pick the location.
Maybe I don't understand, apps that I use that do geo fencing pop up a google map for me to select a location and radius, so we can have client access to a map, yes? Also on Android you have to register for entry/exits events to geo-fence locations, which implies the client does need to store the coordinates and some item to trigger locally. In fact, I believe on each reboot of the device, apps need to listen for a boot complete action (or something) and re-register its geofences. |
FWIW, I'm actually a big fan of having the geofences come entirely from the server -- I'm just not sure of the best mechanism to make that happen. |
Maybe as state of a string item, but thats not the best solution |
I really like proposal 2 of @jjhuff, but that would need some work on the server, wouldn't it? |
Triggering travis |
Looking forward to test this! |
Currently you have to enter the location's coordinates. It would be a lot nicer to fetch them from the server. |
} else { | ||
ComponentName comp = new ComponentName(context.getPackageName(), | ||
GeofenceIntentService.class.getName()); | ||
startWakefulService(context, (intent.setComponent(comp))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if and the else block are 100% equivalent.
I just proposed to implement a new geofence service in the server explaning how any UI could interact with it. |
My proposal has the advantage to have the geofences defined on server side. Using Paper UI, it will be easy to select the locations insde a map (coming feature in openHAB). |
I see that (computation being done server side) as a problem though. When doing it client side, one can leverage OS features (here: Play Services) when determining geofence status. When doing it server side, there's no other option than regularly polling location, which likely is less efficient. |
No problem, we can have a service mode where the geofence status is determined by the client. In this case, the client only call the geofence service when it detects a change of status; the service will not compute the status again but consider the status provided in parameter. |
In case the app only call the server when it enters or leaves a geo-fence, we have no chance to track the position of the person inside openHAB server. Maybe the service could be called by the Android app every XX minutes if the position has changed in order to set a location item. XX should be configurable. |
A geofence is not the same thing as location tracking. The former only provides an in/out information, the latter provides the actual location. We could probably support both modes, but the latter rather sounds like an extension of Location items. |
Location tracking could already be done by any client UI simply by updating a particular location item. That is true that no additional service is required for that. I thought about location tracking because if we have a service that receives the position for geofence computation, it is easy to track position at the same time. But that would be just an option of the service. |
At least the service could allow sharing geofences. It could even be used to save on server side new geofences defined by a client. |
@kaikreuzer rejected my proposal explaning that there is no need to introduce a new geofence "concept" in Eclipse Smarthome because we already have Location item and distance between location items can be computed inside rules. |
... sounds a bit hard, I would say I questioned the suggested way to implement it. But I think implementing this in the client side only isn't too bad as the precision and size of the fence might anyhow depend on the OS. |
d84840f
to
d3ee35c
Compare
Superseded by #914 |
This implements #343
/services/org.eclipse.smarthome.core.i18nprovider/config
to getlocation
. I'd be totally in favor of fetching that another way if there is one. Maybe a new core service to expose for location?I don't do tons of Java or Android, so please tell me what can be improved!