Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Mojio binding #3623

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/.project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.mojio</name>
<comment>This is the Mojio binding of the open Home Automation Bus (openHAB)</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
41 changes: 41 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/META-INF/MANIFEST.MF
@@ -0,0 +1,41 @@
Manifest-Version: 1.0
Private-Package: org.openhab.binding.mojio.internal
Ignore-Package: org.openhab.binding.mojio.internal
Bundle-License: http://www.eclipse.org/legal/epl-v10.html
Bundle-Name: openHAB Mojio Binding
Bundle-SymbolicName: org.openhab.binding.mojio
Bundle-Vendor: openHAB.org
Bundle-Version: 1.8.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.9.0

Bundle-ManifestVersion: 2
Bundle-Description: This is the Mojio binding of the open Home Aut
omation Bus (openHAB)
Import-Package: com.google.common.base,
com.google.common.io,
org.apache.commons.httpclient,
org.apache.commons.httpclient.util,
org.apache.commons.lang,
org.apache.commons.lang.builder,
org.apache.commons.logging,
org.codehaus.jackson,
org.codehaus.jackson.annotate,
org.codehaus.jackson.map,
org.codehaus.jackson.map.annotate,
org.openhab.binding.mojio,
org.openhab.core.binding,
org.openhab.core.events,
org.openhab.core.items,
org.openhab.core.library.items,
org.openhab.core.library.types,
org.openhab.core.types,
org.openhab.io.net.http,
org.openhab.model.item.binding,
org.osgi.framework,
org.osgi.service.cm,
org.osgi.service.component,
org.osgi.service.event,
org.slf4j
Export-Package: org.openhab.binding.mojio
Bundle-DocURL: http://www.openhab.org
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J2SE-1.7

Service-Component: OSGI-INF/binding.xml, OSGI-INF/genericbindingprovider.xml
Bundle-ClassPath: .
22 changes: 22 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/OSGI-INF/binding.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010-2015, openHAB.org and others.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016


All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0" activate="activate" modified="modified" deactivate="deactivate" name="org.openhab.binding.mojio.binding" immediate="true" configuration-pid="org.openhab.mojio" configuration-policy="optional">
<implementation class="org.openhab.binding.mojio.internal.MojioBinding" />

<reference bind="setEventPublisher" cardinality="1..1"
interface="org.openhab.core.events.EventPublisher" name="EventPublisher"
policy="dynamic" unbind="unsetEventPublisher" />
<reference bind="addBindingProvider" cardinality="1..n"
interface="org.openhab.binding.mojio.MojioBindingProvider" name="MojioBindingProvider"
policy="dynamic" unbind="removeBindingProvider" />

</scr:component>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010-2015, openHAB.org and others.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016


All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.openhab.binding.mojio.genericbindingprovider">
<implementation class="org.openhab.binding.mojio.internal.MojioGenericBindingProvider"/>

<service>
<provide interface="org.openhab.model.item.binding.BindingConfigReader"/>
<provide interface="org.openhab.binding.mojio.MojioBindingProvider"/>
</service>

</scr:component>
6 changes: 6 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/build.properties
@@ -0,0 +1,6 @@
source.. = src/main/java/,\
src/main/resources/
bin.includes = META-INF/,\
.,\
OSGI-INF/
output.. = target/classes/
35 changes: 35 additions & 0 deletions bundles/binding/org.openhab.binding.mojio/pom.xml
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.openhab.bundles</groupId>
<artifactId>binding</artifactId>
<version>1.8.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.9.0

</parent>

<name>openHAB Mojio Binding</name>

<properties>
<bundle.symbolicName>org.openhab.binding.mojio</bundle.symbolicName>
<bundle.namespace>org.openhab.binding.mojio</bundle.namespace>
<deb.name>openhab-addon-binding-mojio</deb.name>
<deb.description>${project.name}</deb.description>
</properties>

<modelVersion>4.0.0</modelVersion>
<groupId>org.openhab.binding</groupId>
<artifactId>org.openhab.binding.mojio</artifactId>

<packaging>eclipse-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>org.vafer</groupId>
<artifactId>jdeb</artifactId>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2010-2015, openHAB.org and others.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016

*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.mojio;

import org.openhab.core.binding.BindingProvider;

import org.openhab.binding.mojio.messages.GetVehicleData;
import org.openhab.binding.mojio.messages.VehicleStatusResponse;
import org.openhab.binding.mojio.messages.VehicleType;
import org.openhab.binding.mojio.messages.GetMojioData;
import org.openhab.binding.mojio.messages.MojioStatusResponse;
import org.openhab.binding.mojio.messages.MojioType;

/**
* @author Vladimir Pavluk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this code created by Vladimir Pavluk?

* @since 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.9.0

*/
public interface MojioBindingProvider extends BindingProvider {

String getMojioIMEI(String itemName);

String[] getValuePath(String itemName);

double getItemRate(String itemName);

Class getItemType(String itemName);
}
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2010-2015, openHAB.org and others.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016

*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.mojio.internal;

import org.openhab.binding.mojio.messages.AuthorizeRequest;
import org.openhab.binding.mojio.messages.AuthorizeResponse;
import org.openhab.binding.mojio.messages.MojioTimestamp;
import java.util.Date;

/**
* MojioAuthTag class stores MojIO credentials and the AuthTag along with the expiration date.
* When the tag expires, it updates the tag.
*
* @author Vladimir Pavluk
* @since 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.9.0

*/
public class MojioAuthTag {
String appId;
String appKey;
String username;
String password;
String authToken = "";
MojioTimestamp validUntil;

MojioAuthTag(String appId, String appKey, String username, String password) {
this.appId = appId;
this.appKey = appKey;
this.username = username;
this.password = password;
updateToken();
}

String getAuthToken() {
Date now = new Date();
if(now.compareTo(validUntil.toDate()) > 0) {
updateToken();
}
return authToken;
}

void updateToken() {
final AuthorizeRequest request = new AuthorizeRequest(appId, appKey, username, password);
final AuthorizeResponse response = request.execute();
authToken = response.getAuthToken();
validUntil = response.getValidUntil();
}
}