8000 Hue Bridge by mastermichi · Pull Request #332 · firebirdberlin/nightdream · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Hue Bridge #332

New issue
8000

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation 'androidx.work:work-runtime-ktx:2.7.1'
implementation 'androidx.work:work-multiprocess:2.7.1'
implementation 'com.prof18.rssparser:rssparser:4.0.2'
implementation 'io.github.zeroone3010:yetanotherhueapi:2.7.0'


// https://developer.android.com/studio/build/multidex
Expand Down
39 changes: 39 additions & 0 deletions res/drawable/ic_hue_bridge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="huebridge"
android:tint="@color/blue"
android:width="36dp"
android:height="36dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="air"
android:pathData="M 14.099 6.476 C 15.151 6.476 16.14 6.887 16.882 7.631 C 17.627 8.375 18.036 9.367 18.036 10.422 L 19.658 10.422 C 19.658 7.356 17.164 4.862 14.098 4.862 L 14.098 6.476 L 14.099 6.476 Z M 14.101 3.615 C 17.85 3.615 20.9 6.669 20.9 10.424 L 22.521 10.424 C 22.521 5.779 18.744 2 14.101 2 L 14.101 3.615 L 14.101 3.615 Z M 16.342 9.296"
android:fillColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="bridge"
android:pathData="M 6.093 7.833 L 14.652 7.833 C 15.182 7.833 15.691 8.044 16.066 8.419 C 16.441 8.794 16.652 9.303 16.652 9.833 L 16.652 20 C 16.652 20.53 16.441 21.039 16.066 21.414 C 15.691 21.789 15.182 22 14.652 22 L 6.093 22 C 5.563 22 5.054 21.789 4.679 21.414 C 4.304 21.039 4.093 20.53 4.093 20 L 4.093 9.833 C 4.093 9.303 4.304 8.794 4.679 8.419 C 5.054 8.044 5.563 7.833 6.093 7.833"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="button"
android:pathData="M 10.525 13.423 C 9.998 13.423 9.491 13.629 9.118 13.995 C 8.744 14.361 8.534 14.858 8.534 15.376 C 8.534 15.893 8.744 16.39 9.118 16.756 C 9.491 17.123 9.998 17.328 10.525 17.328 C 10.947 17.33 11.358 17.2 11.699 16.958 C 12.04 16.715 12.295 16.373 12.425 15.98 C 12.555 15.587 12.555 15.164 12.425 14.771 C 12.295 14.378 12.04 14.036 11.699 13.794 C 11.358 13.552 10.947 13.422 10.525 13.423 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_1"
android:pathData="M 7.041 10.054 C 6.828 10.054 6.623 10.138 6.473 10.289 C 6.322 10.44 6.237 10.645 6.237 10.858 C 6.237 11.071 6.322 11.276 6.473 11.426 C 6.623 11.577 6.828 11.662 7.041 11.662 C 7.254 11.662 7.459 11.577 7.61 11.426 C 7.761 11.276 7.845 11.071 7.845 10.858 C 7.845 10.645 7.761 10.44 7.61 10.289 C 7.459 10.138 7.254 10.054 7.041 10.054 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_2"
android:pathData="M 10.411 9.977 C 10.197 9.977 9.993 10.062 9.842 10.213 C 9.691 10.363 9.607 10.568 9.607 10.781 C 9.607 10.994 9.691 11.199 9.842 11.35 C 9.993 11.5 10.197 11.585 10.411 11.585 C 10.624 11.585 10.828 11.5 10.979 11.35 C 11.13 11.199 11.215 10.994 11.215 10.781 C 11.215 10.568 11.13 10.363 10.979 10.213 C 10.828 10.062 10.624 9.977 10.411 9.977 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_3"
android:pathData="M 13.78 9.977 C 13.567 9.977 13.362 10.062 13.211 10.213 C 13.061 10.363 12.976 10.568 12.976 10.781 C 12.976 10.994 13.061 11.199 13.211 11.35 C 13.362 11.5 13.567 11.585 13.78 11.585 C 13.993 11.585 14.198 11.5 14.349 11.35 C 14.499 11.199 14.584 10.994 14.584 10.781 C 14.584 10.568 14.499 10.363 14.349 10.213 C 14.198 10.062 13.993 9.977 13.78 9.977 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
</vector>
34 changes: 34 additions & 0 deletions res/drawable/ic_hue_bridge_connect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="huebridge"
android:tint="@color/blue"
android:width="36dp"
android:height="36dp"
android:viewportWidth="20"
android:viewportHeight="24">
<path
android:name="bridge"
android:pathData="M 6.093 7.833 L 14.652 7.833 C 15.182 7.833 15.691 8.044 16.066 8.419 C 16.441 8.794 16.652 9.303 16.652 9.833 L 16.652 20 C 16.652 20.53 16.441 21.039 16.066 21.414 C 15.691 21.789 15.182 22 14.652 22 L 6.093 22 C 5.563 22 5.054 21.789 4.679 21.414 C 4.304 21.039 4.093 20.53 4.093 20 L 4.093 9.833 C 4.093 9.303 4.304 8.794 4.679 8.419 C 5.054 8.044 5.563 7.833 6.093 7.833"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="button"
android:pathData="M 10.525 13.423 C 9.998 13.423 9.491 13.629 9.118 13.995 C 8.744 14.361 8.534 14.858 8.534 15.376 C 8.534 15.893 8.744 16.39 9.118 16.756 C 9.491 17.123 9.998 17.328 10.525 17.328 C 10.947 17.33 11.358 17.2 11.699 16.958 C 12.04 16.715 12.295 16.373 12.425 15.98 C 12.555 15.587 12.555 15.164 12.425 14.771 C 12.295 14.378 12.04 14.036 11.699 13.794 C 11.358 13.552 10.947 13.422 10.525 13.423 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_1"
android:pathData="M 7.041 10.054 C 6.828 10.054 6.623 10.138 6.473 10.289 C 6.322 10.44 6.237 10.645 6.237 10.858 C 6.237 11.071 6.322 11.276 6.473 11.426 C 6.623 11.577 6.828 11.662 7.041 11.662 C 7.254 11.662 7.459 11.577 7.61 11.426 C 7.761 11.276 7.845 11.071 7.845 10.858 C 7.845 10.645 7.761 10.44 7.61 10.289 C 7.459 10.138 7.254 10.054 7.041 10.054 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_2"
android:pathData="M 10.411 9.977 C 10.197 9.977 9.993 10.062 9.842 10.213 C 9.691 10.363 9.607 10.568 9.607 10.781 C 9.607 10.994 9.691 11.199 9.842 11.35 C 9.993 11.5 10.197 11.585 10.411 11.585 C 10.624 11.585 10.828 11.5 10.979 11.35 C 11.13 11.199 11.215 10.994 11.215 10.781 C 11.215 10.568 11.13 10.363 10.979 10.213 C 10.828 10.062 10.624 9.977 10.411 9.977 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
<path
android:name="lights_3"
android:pathData="M 13.78 9.977 C 13.567 9.977 13.362 10.062 13.211 10.213 C 13.061 10.363 12.976 10.568 12.976 10.781 C 12.976 10.994 13.061 11.199 13.211 11.35 C 13.362 11.5 13.567 11.585 13.78 11.585 C 13.993 11.585 14.198 11.5 14.349 11.35 C 14.499 11.199 14.584 10.994 14.584 10.781 C 14.584 10.568 14.499 10.363 14.349 10.213 C 14.198 10.062 13.993 9.977 13.78 9.977 Z"
android:strokeColor="#FF000000"
android:strokeWidth="1"/>
</vector>
24 changes: 24 additions & 0 deletions res/layout/hue_connect_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_hue_bridge_connect"
android:contentDescription="Push button to connect" />

</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 11 additions & 0 deletions res/xml-v14/preferences_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ vi - Phong Nguyen"/>
/>
</Preference>

<Preference
app:iconSpaceReserved="false"
app:key="about_hue_api"
app:summary="by ZeroOne3010"
app:title="Hue Api">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/ZeroOne3010/yetanotherhueapi"
/>
</Preference>

</PreferenceCategory>

<PreferenceCategory
Expand Down
23 changes: 22 additions & 1 deletion res/xml-v14/preferences_smarthome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
app:key="cat_avmfritz"
app:title="@string/smart_home_avm">


<EditTextPreference
android:defaultValue="http://fritz.box"
android:key="smart_home_avm_host"
Expand Down Expand Up @@ -42,7 +41,29 @@
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true"
/>
</PreferenceCategory>

<PreferenceCategory
app:iconSpaceReserved="true"
app:layout="@layout/preferences_category"
app:key="cat_hue"
app:title="Hue">

<SwitchPreferenceCompat
app:iconSpaceReserved="false"
app:defaultValue="false"
app:key="switchHue"
app:summary=""
app:title="Hue Bridge"
app:icon="@drawable/ic_hue_bridge_connect"/>

<com.firebirdberlin.nightdream.ui.HueConnectPreference
app:iconSpaceReserved="false"
app:enabled="false"
android:key="connectHue"
android:title="Connect to Hue"
android:summary="not connected"
/>

</PreferenceCategory>
</PreferenceScreen>
52 changes: 52 additions & 0 deletions src/com/firebirdberlin/HueApi/HueBridgeSearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.firebirdberlin.HueApi;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import io.github.zeroone3010.yahueapi.discovery.HueBridgeDiscoveryService;

public class HueBridgeSearch extends Worker {
private static final String TAG = "HueBridgeSearch";

public HueBridgeSearch(@NonNull Context context, @NonNull WorkerParameters params) {
super(context, params);
}

@NonNull
@Override
public Result doWork() {
Log.d(TAG, "HueBridgeSearch doWork()");

Future<List<io.github.zeroone3010.yahueapi.HueBridge>> bridgesFuture = new HueBridgeDiscoveryService()
.discoverBridges(bridge -> Log.d(TAG, "ppt Bridge found: " + bridge));
final List<io.github.zeroone3010.yahueapi.HueBridge> bridges;
try {
bridges = bridgesFuture.get();
if (!bridges.isEmpty()) {
final String bridgeIp = bridges.get(0).getIp();
Log.d(TAG, "Bridge found at " + bridgeIp);
// Then follow the code snippets below under the "Once you have a Bridge IP address" header
Data myData = new Data.Builder()
.putString("bridgeIP", bridgeIp)
.build();
return Result.success(myData);
}
} catch (ExecutionException e) {
e.printStackTrace();
return Result.failure();
} catch (InterruptedException e) {
e.printStackTrace();
return Result.failure();
}
return Result.success();
}
}
Loading
0