Skip to content

Commit

Permalink
Merge pull request #15 from jeedom/beta
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
zoic21 authored Feb 12, 2024
2 parents 60edac0 + 99f05eb commit bf1f086
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 31 deletions.
127 changes: 99 additions & 28 deletions core/class/netatmo_energy.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@

class netatmo_energy {

public static function getRoomDevice($_modules,$_module_ids){
$return = '';
public static function getRoomEnergyDevices($_modules,$_module_ids){
foreach ($_modules as $module) {
if(!in_array($module['id'],$_module_ids)){
continue;
}
if($module['type'] == 'NRV'){
return 'NRV';
}else{
$return = $module['type'];
if(!in_array($module['type'],array('NRV','NATherm1','OTM'))){
continue;
}
$return[] = ['type' => $module['type'], 'bridge' => $module['bridge']];
}
return $return;
}

public static function sync(){
$homesdata = netatmo::request('/homesdata');
log::add('netatmo','debug','[netatmo energy] '.json_encode($homesdata));
log::add('netatmo','debug','[netatmo energy] homesdata : '.json_encode($homesdata));
if(isset($homesdata['homes']) && count($homesdata['homes']) > 0){
foreach ($homesdata['homes'] as $home) {
if(!isset($home['rooms']) || count($home['rooms']) == 0 || !isset($home['modules']) || count($home['modules']) == 0 || !isset($home['schedules'])){
Expand Down Expand Up @@ -72,12 +70,29 @@ public static function sync(){
}
}
}

$bridges = array();
foreach ($home['modules'] as $module) {
if(!in_array($module['type'],array('NAPlug','OTH'))){
continue;
}
$bridges[$module['id']] = $module['type'];
}

foreach ($home['rooms'] as $room) {
if(count($room['module_ids']) == 0){
continue;
}
$device = self::getRoomDevice($home['modules'],$room['module_ids']);
if(!in_array($device,array('NRV','NATherm1'))){
$devices = self::getRoomEnergyDevices($home['modules'],$room['module_ids']);
$room_devices_list = array();
foreach ($devices as $device) {
$room_devices_list[] = $device[type];
}
$room_devices_list = implode(", ",$room_devices_list);
$eqLogic->setConfiguration('equipements',$devices_room_list);
$device = $devices[0]['type'];

if(!in_array($devices[0]['type'],array('NRV','NATherm1','OTM'))){
continue;
}
$eqLogic = eqLogic::byLogicalId($room['id'], 'netatmo');
Expand All @@ -93,15 +108,21 @@ public static function sync(){
$eqLogic->setLogicalId($room['id']);
$eqLogic->setConfiguration('device', $device);
$eqLogic->setConfiguration('home_id', $home['id']);
$eqLogic->setConfiguration('devices-count', count($devices));
$eqLogic->setConfiguration('bridge', $devices[0]['bridge']);
$eqLogic->setConfiguration('bridge_type', $bridges[$devices[0]['bridge']]);
$eqLogic->save();
}
}
}
self::refresh();
self::refresh($homesdata);
}

public static function refresh(){
$homesdata = netatmo::request('/homesdata');
public static function refresh($homesdata = null){
if($homesdata == null) {
$homesdata = netatmo::request('/homesdata');
log::add('netatmo','debug','[netatmo energy] homesdata : '.json_encode($homestatus));
}
$home_ids = array();
if(isset($homesdata['homes']) && count($homesdata['homes']) > 0){
foreach ($homesdata['homes'] as $home) {
Expand All @@ -116,7 +137,7 @@ public static function refresh(){
if(!is_object($eqLogic)){
continue;
}
if($home['therm_mode'] != 'schedule'){
if($home['therm_mode'] != 'schedule'){
$eqLogic->checkAndUpdateCmd('mode',$home['therm_mode']);
continue;
}
Expand All @@ -137,7 +158,25 @@ public static function refresh(){
}
foreach ($home_ids as $home_id) {
$homestatus = netatmo::request('/homestatus',array('home_id' => $home_id));
log::add('netatmo','debug','[netatmo energy] homestatus : '.json_encode($homestatus));
log::add('netatmo','debug','[netatmo energy] homestatus : '.json_encode($homestatus));
if(isset($homestatus['home']) && isset($homestatus['home']['modules']) && count($homestatus['home']['modules']) > 0){
foreach ($homestatus['home']['modules'] as $module) {
$eqLogic = eqLogic::byLogicalId($module['id'], 'netatmo');
if(!is_object($eqLogic)){
continue;
}
foreach ($eqLogic->getCmd('info') as $cmd) {
$logicalId = $cmd->getLogicalId();
if($logicalId == 'state'){
$logicalId = 'status';
}
if(!isset($module[$logicalId])){
continue;
}
$eqLogic->checkAndUpdateCmd($cmd,$module[$logicalId]);
}
}
}
if(isset($homestatus['home']) && isset($homestatus['home']['rooms']) && count($homestatus['home']['rooms']) > 0){
foreach ($homestatus['home']['rooms'] as $room) {
$eqLogic = eqLogic::byLogicalId($room['id'], 'netatmo');
Expand All @@ -156,24 +195,56 @@ public static function refresh(){
}
}
}
}



}
}

public static function execCmd($_cmd,$_options = array()){
$eqLogic = $_cmd->getEqLogic();
if($_cmd->getLogicalId() == 'setpoint'){
netatmo::request('/setroomthermpoint',array(
'home_id' => $eqLogic->getConfiguration('home_id'),
'room_id' => $eqLogic->getLogicalId(),
'mode' => 'manual',
'temp' => $_options['slider'],
),'POST');
if($eqLogic->getConfiguration('bridge_type') == 'OTH'){
netatmo::request('/setstate',array(
'home' => array(
'id' => $eqLogic->getConfiguration('home_id'),
'rooms' => array(
array(
'id' => $eqLogic->getLogicalId(),
'therm_setpoint_mode' => 'manual',
'therm_setpoint_temperature' => intval($_options['slider']),
)
)
)
),'POST');
}else{
netatmo::request('/setroomthermpoint',array(
'home_id' => $eqLogic->getConfiguration('home_id'),
'room_id' => $eqLogic->getLogicalId(),
'mode' => 'manual',
'temp' => $_options['slider'],
),'POST');
}
}else if($_cmd->getLogicalId() == 'mode_auto'){
netatmo::request('/setroomthermpoint',array(
'home_id' => $eqLogic->getConfiguration('home_id'),
'room_id' => $eqLogic->getLogicalId(),
'mode' => 'home',
),'POST');
if($eqLogic->getConfiguration('bridge_type') == 'OTH'){
netatmo::request('/setstate',array(
'home' => array(
'id' => $eqLogic->getConfiguration('home_id'),
'rooms' => array(
array(
'id' => $eqLogic->getLogicalId(),
'therm_setpoint_mode' => 'home'
)
)
)
),'POST');
}else{
netatmo::request('/setroomthermpoint',array(
'home_id' => $eqLogic->getConfiguration('home_id'),
'room_id' => $eqLogic->getLogicalId(),
'mode' => 'home',
),'POST');
}
}else if($_cmd->getLogicalId() == 'home_mode_away'){
netatmo::request('/setthermmode',array(
'home_id' => $eqLogic->getConfiguration('home_id'),
Expand All @@ -193,7 +264,7 @@ public static function execCmd($_cmd,$_options = array()){
'schedule_id' => str_replace('schedule','',$_cmd->getLogicalId())
),'POST');
}
sleep(2);
self::sync();
sleep(10);
self::refresh();
}
}
2 changes: 1 addition & 1 deletion core/class/netatmo_security.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static function execCmd($_cmd,$_options = array()){
$request_http = new com_http($eqLogic->getCache('vpnUrl').'/command/floodlight_set_config?config='.urlencode('{"mode":"auto"}'));
$request_http->exec(5, 1);
}
sleep(2);
sleep(10);
self::refresh();
}
}
1 change: 1 addition & 0 deletions core/config/devices/NSD.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "Fumée",
"type": "info",
"subtype": "binary",
"generic_type": "SMOKE",
"isVisible": 1,
"isHistorized": 0,
"logicalId": "smoke",
Expand Down
96 changes: 96 additions & 0 deletions core/config/devices/OTM.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name" : "Thermostat open therm",
"commands" : [
{
"name": "Anticipation",
"type": "info",
"subtype": "binary",
"isVisible": 1,
"isHistorized": 0,
"logicalId": "anticipating",
"configuration": {
"repeatEventManagement": "always"
}
},
{
"name": "Fenêtre ouverte",
"type": "info",
"subtype": "binary",
"isVisible": 1,
"isHistorized": 0,
"logicalId": "open_window",
"configuration": {
"repeatEventManagement": "always"
}
},
{
"name": "Température",
"type": "info",
"subtype": "numeric",
"isVisible": 1,
"isHistorized": 1,
"unite" : "°C",
"generic_type" : "THERMOSTAT_TEMPERATURE",
"logicalId": "therm_measured_temperature"
},
{
"name": "Mode",
"type": "info",
"subtype": "string",
"isVisible": 1,
"isHistorized": 0,
"generic_type" : "THERMOSTAT_MODE",
"logicalId": "therm_setpoint_mode"
},
{
"name": "Consigne",
"type": "info",
"subtype": "numeric",
"isVisible": 0,
"isHistorized": 0,
"unite" : "°C",
"generic_type" : "THERMOSTAT_SETPOINT",
"logicalId": "therm_setpoint_temperature",
"template": {
"dashboard" : "button",
"mobile" : "button"
}
},
{
"name": "Thermostat",
"type": "action",
"subtype": "slider",
"isVisible": 1,
"isHistorized": 0,
"unite" : "°C",
"value" : "Consigne",
"generic_type" : "THERMOSTAT_SET_SETPOINT",
"template" : {
"dashboard" : "button",
"mobile" : "button"
},
"configuration" : {
"minValue" : 10,
"maxValue" : 35
},
"logicalId": "setpoint"
},
{
"name": "Auto",
"type": "action",
"subtype": "other",
"isVisible": 1,
"isHistorized": 0,
"generic_type" : "THERMOSTAT_SET_MODE",
"logicalId": "mode_auto"
},
{
"name": "Etat chauffe",
"type": "info",
"subtype": "numeric",
"isVisible": 1,
"isHistorized": 0,
"logicalId": "boiler_status"
}
]
}
Binary file added core/config/devices/OTM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions desktop/js/netatmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ $('.eqLogicAttr[data-l1key=configuration][data-l2key=device]').on('change',funct
} else {
$('#battery_net_weather').show();
}
if(['NATherm1','NaMain','NAModule1','NAModule2','NAModule3','NAModule4'].includes($(this).value())){
$('.eqLogicAttr[data-l1key=configuration][data-l2key=firmware]').parent().parent().show();
}else{
$('.eqLogicAttr[data-l1key=configuration][data-l2key=firmware]').parent().parent().hide();
}

if(['NATherm1','OTM','NRV'].includes($(this).value())){
$('.eqLogicAttr[data-l1key=configuration][data-l2key=bridge_type]').parent().parent().show();
$('.eqLogicAttr[data-l1key=configuration][data-l2key=bridge]').parent().parent().show();
$('.eqLogicAttr[data-l1key=configuration][data-l2key=devices-count]').parent().parent().show();
}else{
$('.eqLogicAttr[data-l1key=configuration][data-l2key=bridge_type]').parent().parent().hide();
$('.eqLogicAttr[data-l1key=configuration][data-l2key=bridge]').parent().parent().hide();
$('.eqLogicAttr[data-l1key=configuration][data-l2key=devices-count]').parent().parent().hide();
}
});

$('#bt_syncEqLogicNetatmo').off('click').on('click', function () {
Expand Down Expand Up @@ -77,6 +92,7 @@ function addCmdToTable(_cmd) {
tr += '<td>';
tr += '<label class="checkbox-inline"><input type="checkbox" class="cmdAttr" data-l1key="isVisible" checked/>{{Afficher}}</label> '
tr += '<label class="checkbox-inline"><input type="checkbox" class="cmdAttr" data-l1key="isHistorized" checked/>{{Historiser}}</label> '
tr += '<label class="checkbox-inline"><input type="checkbox" class="cmdAttr" data-l1key="display" data-l2key="invertBinary"/>{{Inverser}}</label> '
tr += '<div style="margin-top:7px;">'
tr += '<input class="tooltips cmdAttr form-control input-sm" data-l1key="configuration" data-l2key="minValue" placeholder="{{Min}}" title="{{Min}}" style="width:30%;max-width:80px;display:inline-block;margin-right:2px;">'
tr += '<input class="tooltips cmdAttr form-control input-sm" data-l1key="configuration" data-l2key="maxValue" placeholder="{{Max}}" title="{{Max}}" style="width:30%;max-width:80px;display:inline-block;margin-right:2px;">'
Expand Down
Loading

0 comments on commit bf1f086

Please sign in to comment.