Smart Home Tem

This commit is contained in:
JonatanRek 2020-05-03 18:58:41 +02:00
parent 8f13c7ee5d
commit 6383034de1
2 changed files with 161 additions and 8 deletions

View File

@ -30,10 +30,10 @@ class GoogleHomeApi {
}
static function query($requestId, $payload){
$devices = [];
foreach ($payload['devices'] as $deviceId) {
$subDeviceData = SubDeviceManager::getSubDevice($deviceId['id']);
if ($subDeviceData['type'] != "on/off") continue;
if ($subDeviceData['type'] != "on/off" && $subDeviceData['type'] != "temp_cont") continue;
$state = false;
if (RecordManager::getLastRecord($deviceId['id'])['value'] == 1){
@ -47,13 +47,24 @@ class GoogleHomeApi {
$status = 'SUCCESS';
}
$devices[] = [
$tempDevice = [
$deviceId['id'] => [
'on' => $state,
'online' => $online,
'status'=> $status,
]
];
if ($subDeviceData['type'] == "temp_cont"){
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = RecordManager::getLastRecord($deviceId['id'])['value'];
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = RecordManager::getLastRecord($deviceId['id'])['value'];
} else {
$tempDevice[$deviceId['id']]['on'] = $state;
}
$devices = $tempDevice;
if (count($devices)> 1){
$devices[] = $tempDevice;
}
}
@ -77,21 +88,52 @@ class GoogleHomeApi {
foreach ($devicesData as $deviceKey => $deviceData) {
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']);
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
if ($subDeviceData['type'] != "on/off") continue;
$devices[] = [
if ($subDeviceData['type'] != "on/off" && $subDeviceData['type'] != "temp_cont") continue;
$tempDevice = [
'id' => (string) $subDeviceData['subdevice_id'],
'type' => 'action.devices.types.OUTLET',
'traits' => [ 'action.devices.traits.OnOff' ],
'type' => GoogleHomeDeviceTypes::getEquivalent($subDeviceData['type']),
'name' => [
'name' => $deviceData['name'],
],
'willReportState' => false,
'roomHint' => $roomData['name']
];
//traids
switch ($subDeviceData['type']) {
case 'on/off':
$tempDevice['traits'] = [ 'action.devices.traits.OnOff' ];
break;
case 'temp_cont':
$tempDevice['attributes'] = [
"availableThermostatModes" => "off,heat,on",
"thermostatTemperatureRange" => [
'minThresholdCelsius' => 5,
'maxThresholdCelsius' => 15,
],
"thermostatTemperatureUnit" => "C",
"commandOnlyTemperatureSetting" => false,
"queryOnlyTemperatureSetting" => false,
"bufferRangeCelsius" => 0,
];
$tempDevice['traits'] = [
'action.devices.traits.TemperatureSetting',
];
break;
}
$devices[] = $tempDevice;
}
}
}
$response = [
'requestId' => $requestId,
'payload' => [
@ -143,6 +185,35 @@ class GoogleHomeApi {
$commands[] = $commandTemp;
break;
case 'action.devices.commands.ThermostatTemperatureSetpoint':
$value = 0;
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) $value = $executionCommand['params']['thermostatTemperatureSetpoint'];
RecordManager::createWithSubId($subDeviceId, $value);
$timeout = 0;
while(RecordManager::getLastRecord($subDeviceId)['execuded'] == 0 && $timeout < 5 ){
sleep(1);
$timeout++;
}
$commandTemp = [
'ids' => [$subDeviceId],
'status' => 'SUCCESS',
'states' => [
'thermostatMode' => 'heat',
'thermostatTemperatureSetpoint' => $value,
'thermostatTemperatureAmbient' => $value,
],
];
if ($timeout >= 5){
$commandTemp['status'] = "OFFLINE";
}
$commands[] = $commandTemp;
break;
}
}
}

View File

@ -0,0 +1,82 @@
<?php
class GoogleHomeDeviceTypes {
private static $wordBook = [
'on/off' => 'action.devices.types.OUTLET',
'temp_cont' => 'action.devices.types.THERMOSTAT',
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
const AirFreshener = 'action.devices.types.AIRFRESHENER';
const AirPurifier = 'action.devices.types.AIRPURIFIER';
const Awning = 'action.devices.types.AWNING';
const Bathtub = 'action.devices.types.BATHTUB';
const Bed = 'action.devices.types.BED';
const Blender = 'action.devices.types.BLENDER';
const Blinds = 'action.devices.types.BLINDS';
const Boiler = 'action.devices.types.BOILER';
const Camera = 'action.devices.types.CAMERA';
const CarbonMonoxideDetector = 'action.devices.types.CARBON_MONOXIDE_DETECTOR';
const Charger = 'action.devices.types.CHARGER';
const Closet = 'action.devices.types.CLOSET';
const CoffeeMaker = 'action.devices.types.COFFEE_MAKER';
const Cooktop = 'action.devices.types.COOKTOP';
const Curtain = 'action.devices.types.CURTAIN';
const Dehumidifier = 'action.devices.types.DEHUMIDIFIER';
const Dehydrator = 'action.devices.types.DEHYDRATOR';
const Dishwasher = 'action.devices.types.DISHWASHER';
const Door = 'action.devices.types.DOOR';
const Drawer = 'action.devices.types.DRAWER';
const Dryer = 'action.devices.types.DRYER';
const Fan = 'action.devices.types.FAN';
const Faucet = 'action.devices.types.FAUCET';
const Fireplace = 'action.devices.types.FIREPLACE';
const Fryer = 'action.devices.types.FRYER';
const GarageDoor = 'action.devices.types.GARAGE';
const Gate = 'action.devices.types.GATE';
const Grill = 'action.devices.types.GRILL';
const Heater = 'action.devices.types.HEATER';
const Hood = 'action.devices.types.HOOD';
const Humidifier = 'action.devices.types.HUMIDIFIER';
const Kettle = 'action.devices.types.KETTLE';
const Light = 'action.devices.types.LIGHT';
const Lock = 'action.devices.types.LOCK';
const MediaRemote = 'action.devices.types.REMOTECONTROL';
const Mop = 'action.devices.types.MOP';
const Mower = 'action.devices.types.MOWER';
const Microwave = 'action.devices.types.MICROWAVE';
const Multicooker = 'action.devices.types.MULTICOOKER';
const Network = 'action.devices.types.NETWORK';
const Oven = 'action.devices.types.OVEN';
const Pergola = 'action.devices.types.PERGOLA';
const PetFeeder = 'action.devices.types.PETFEEDER';
const PressureCooker = 'action.devices.types.PRESSURECOOKER';
const Radiator = 'action.devices.types.RADIATOR';
const Refrigerator = 'action.devices.types.REFRIGERATOR';
const Router = 'action.devices.types.ROUTER';
const Scene = 'action.devices.types.SCENE';
const Sensor = 'action.devices.types.SENSOR';
const SecuritySystem = 'action.devices.types.SECURITYSYSTEM';
const SettopBox = 'action.devices.types.SETTOP';
const Shutter = 'action.devices.types.SHUTTER';
const Shower = 'action.devices.types.SHOWER';
const SmokeDetector = 'action.devices.types.SMOKE_DETECTOR';
const SousVide = 'action.devices.types.SOUSVIDE';
const Sprinkler = 'action.devices.types.SPRINKLER';
const StandMixer = 'action.devices.types.STANDMIXER';
const Switch = 'action.devices.types.SWITCH';
const Television = 'action.devices.types.TV';
const Thermostat = 'action.devices.types.THERMOSTAT';
const Vacuum = 'action.devices.types.VACUUM';
const Valve = 'action.devices.types.VALVE';
const Washer = 'action.devices.types.WASHER';
const WaterHeater = 'action.devices.types.WATERHEATER';
const WaterPurifier = 'action.devices.types.WATERPURIFIER';
const WaterSoftener = 'action.devices.types.WATERSOFTENER';
const Window = 'action.devices.types.WINDOW';
const YogurtMaker = 'action.devices.types.YOGURTMAKER';*/
];
static function getEquivalent($type){
return self::$wordBook[$type];
}
}