Skip to content

Commit

Permalink
Merge pull request #4 from saniho/addDataVolume
Browse files Browse the repository at this point in the history
add data volume
  • Loading branch information
saniho authored Feb 23, 2022
2 parents 1593239 + 97c6092 commit c5dcf73
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 62 deletions.
34 changes: 26 additions & 8 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# apiEarnApp

Objectif, recuperer le montant earnApp
Objectif, recuperer le montant earnApp

config yaml
```
- platform: apiEarnApp
token: xxx
scan_interval: 120
```

pour la recupération du token :

ouvrir : https://earnapp.com/dashboard

et dans l'outil de developpement chrome

et recuperer le token : oauth-refresh-token

![](img/token.png)
3 changes: 3 additions & 0 deletions custom_components/apiEarnApp/apiEarnApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def getInfo(self):
def getMoney(self):
return self._money.get("balance",0)

def getTotalMoney(self):
return self._money.get("earnings_total",0)

def getData(self):
vol = 0
for device in self._devices:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apiEarnApp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
# delai pour l'update http, toutes les 3 heures
SCAN_INTERVAL_http = datetime.timedelta(seconds=60*60*3)

__VERSION__ = "1.0.0.2"
__VERSION__ = "1.0.0.4"

__name__ = "apiEarnApp"
33 changes: 1 addition & 32 deletions custom_components/apiEarnApp/earnApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def login(self, token: str, method: str="google") -> bool:
# return the right value depending on succeeding/failing
return True
return False

def userData(self) -> dict:
"""
Get data about the logged in user
Expand Down Expand Up @@ -116,37 +116,6 @@ def transactions(self) -> dict:

resp = makeEarnAppRequest("transactions", "GET", self.cookies) # get all transactions

try:
jsonData = resp.json() # attempt to get the JSON data
except:
return None # if it failed return NoneType
return jsonData

def linkDevice(self, deviceID: str) -> dict:
"""
Link a device to the logged in EarnApp account
:param deviceID: EarnApp device ID to link to account
:return: a dictionary containing error message/success
"""

resp = makeEarnAppRequest("link_device", "POST", self.cookies, {"uuid": deviceID}) # send request

try:
jsonData = resp.json() # attempt to get the JSON data
except:
return None # if it failed return NoneType
return jsonData

def redeemDetails(self, toEmail: str, paymentMethod: str="paypal.com") -> dict:
"""
Change the redeem details of the logged in account
:param toEmail: The email address to send payment to
:param paymentMethod: optional payment method to send via
:return: a dictionary containing error message/success
"""

resp = makeEarnAppRequest("redeem_details", "POST", self.cookies, {"to": toEmail, "payment_method": paymentMethod}) # send request

try:
jsonData = resp.json() # attempt to get the JSON data
except:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apiEarnApp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "apiEarnApp",
"name": "apiEarnApp sensor",
"documentation": "",
"version": "1.0.0.2",
"version": "1.0.0.4",
"requirements": [
],
"dependencies": [],
Expand Down
50 changes: 49 additions & 1 deletion custom_components/apiEarnApp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def getmyEarnApp(self):
def getMoney(self):
return self._myEarnApp.getMoney()

def getTotalMoney(self):
return self._myEarnApp.getTotalMoney()

def getData(self):
return self._myEarnApp.getData()

Expand All @@ -84,6 +87,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
myEarn = myEarnApp( token, update_interval )
myEarn.update()
add_entities([infoEanAppSensorMoney(session, name, update_interval, myEarn )], True)
add_entities([infoEanAppSensorTotalMoney(session, name, update_interval, myEarn )], True)
add_entities([infoEanAppSensorData(session, name, update_interval, myEarn )], True)

class infoEanAppSensorMoney(Entity):
Expand Down Expand Up @@ -118,7 +122,51 @@ def unit_of_measurement(self):
def _update(self):
"""Update device state."""
self._myEarn.update()
self._state, self._attributes = self._sAM.getstatus()
self._state, self._attributes = self._sAM.getstatusMoney()

@property
def device_state_attributes(self):
"""Return the state attributes."""
return self._attributes

@property
def icon(self):
"""Icon to use in the frontend."""
return ICON

class infoEanAppSensorTotalMoney(Entity):
"""."""

def __init__(self, session, name, interval, myEarn):
"""Initialize the sensor."""
self._session = session
self._name = name
self._myEarn = myEarn
self._attributes = None
self._state = None
self.update = Throttle(interval)(self._update)
self._sAM = sensorApiEarnApp.manageSensorState()
self._sAM.init( self._myEarn )

@property
def name(self):
"""Return the name of the sensor."""
return "myEarnApp.totalMoney"

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return "$"

def _update(self):
"""Update device state."""
self._myEarn.update()
self._state, self._attributes = self._sAM.getstatusTotalMoney()

@property
def device_state_attributes(self):
Expand Down
13 changes: 12 additions & 1 deletion custom_components/apiEarnApp/sensorApiEarnApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def init(self, _myEarnApp, _LOGGER=None, version=None):
self._LOGGER = _LOGGER
self.version = version

def getstatus(self):
def getstatusMoney(self):
state = "unavailable"
status_counts = defaultdict(int)
status_counts["version"] = self.version
Expand All @@ -40,6 +40,17 @@ def getstatus(self):
self._state = self._myEarnApp.getMoney()
return self._state, self._attributes

def getstatusTotalMoney(self):
state = "unavailable"
status_counts = defaultdict(int)
status_counts["version"] = self.version

status_counts["version"] = __VERSION__
status_counts["amount"] = self._myEarnApp.getTotalMoney()
self._attributes = status_counts
self._state = self._myEarnApp.getTotalMoney()
return self._state, self._attributes

def getstatusData(self):
state = "unavailable"
status_counts = defaultdict(int)
Expand Down
17 changes: 0 additions & 17 deletions custom_components/apiEarnApp/testapiEarnApp.py

This file was deleted.

24 changes: 24 additions & 0 deletions testapiEarnApp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def testMoney():
from custom_components.apiEarnApp import apiEarnApp, sensorApiEarnApp

_myEarn = apiEarnApp.apiEarnApp()

import configparser
mon_conteneur = configparser.ConfigParser()
mon_conteneur.read("../myCredential/security.txt")
print( mon_conteneur.keys)
token = mon_conteneur["EARNAPP"]['TOKEN']
_myEarn.setToken( token )
_myEarn.getInfo()
print(_myEarn.getMoney())
sAM = sensorApiEarnApp.manageSensorState()
sAM.init(_myEarn )
state, attributes = sAM.getstatusMoney()
sensorApiEarnApp.logSensorState( attributes )
state, attributes = sAM.getstatusTotalMoney()
sensorApiEarnApp.logSensorState( attributes )
state, attributes = sAM.getstatusData()
sensorApiEarnApp.logSensorState( attributes )


testMoney()

0 comments on commit c5dcf73

Please sign in to comment.