Commit 0c915904 authored by Thomas Eimers's avatar Thomas Eimers

Display pump and heating as binary_sensors with Autodiscovery

parent 4edc754f
Pipeline #94936964 failed with stages
in 13 minutes and 9 seconds
......@@ -103,9 +103,12 @@ class HeatingManagementService
} elseif ($newBurnerStatus === false) {
$this->turnBurnerOff();
}
$this->controlPump();
$this->storeWarmwaterUsage();
$this->turnBurnerOn();
$this->turnPumpOn();
}
/**
......@@ -268,7 +271,10 @@ class HeatingManagementService
{
$this->logger->info("Brenner wird EIN geschaltet");
$this->saveLastBurnerStatus(true);
$this->relayService->setRelay($this->config[self::RELAY_CONFIG][RelayState::BURNER_KEY], RelayService::IO_VALUE_ON);
$this->relayService->setRelay(
$this->config[self::RELAY_CONFIG][RelayState::BURNER_KEY],
RelayService::IO_VALUE_ON
);
}
public function saveLastBurnerStatus(bool $status)
......
......@@ -2,8 +2,8 @@
namespace HeatingControl\Service;
use HeatingControl\State\StoreQueueInterface;
use HeatingControl\State\State;
use HeatingControl\State\StoreQueueInterface;
use Mosquitto\Client;
use Psr\Log\LoggerInterface;
......@@ -36,7 +36,7 @@ class SensorStoreMqqt implements SensorStoreInterface
continue;
}
$this->getClient()->loop(1000);
/** @var StoreQueueInterface $sensorValue */
$sensorValue->publishQueueDiscovery($this->getClient());
$sensorStateUrl = $sensorValue->publishQueueValue($this->getClient());
......
......@@ -4,21 +4,19 @@ namespace HeatingControl\State;
use Mosquitto\Client;
trait QueueUrls
trait MessageQueueTrait
{
protected function getQueueDiscoveryUrl()
{
return static::SENSOR_PREFIX . $this->getId() . '/heating/config';
return static::SENSOR_PREFIX . $this->getId() . '/config';
}
public function getQueueStateUrl(): string
{
return static::SENSOR_PREFIX . $this->getId() . '/heating/state';
return static::SENSOR_PREFIX . $this->getId() . '/state';
}
/**
* Das muss hier raus
*
* @param Client $client
* @return string
*/
......@@ -26,10 +24,14 @@ trait QueueUrls
{
$client->publish(
$this->getQueueStateUrl(),
(string)$this->getValue()
(string)$this->getQueueValue()
);
return $this->getQueueStateUrl();
}
public function getQueueValue(): string
{
return (parent::getValue() == 1) ? 'ON' : 'OFF';
}
}
......@@ -9,6 +9,8 @@ use Mosquitto\Client;
*/
class RelayState extends SwitchState implements StoreQueueInterface, StoreRrdInterface
{
use MessageQueueTrait;
const SENSOR_PREFIX = 'homeassistant/binary_sensor/';
const DIAGRAM_PUMP_ID = 9;
......@@ -17,14 +19,24 @@ class RelayState extends SwitchState implements StoreQueueInterface, StoreRrdInt
const BURNER_KEY = 'burner';
const PUMP_KEY = 'pump';
public function publishQueueDiscovery($client): string
public function publishQueueDiscovery(Client $client): string
{
$deviceClass = '';
if ($this->getName() == self::BURNER_KEY) {
$deviceClass = 'heat';
}
if ($this->getName() == self::PUMP_KEY) {
$deviceClass = 'motion';
}
$client->publish(
$this->getQueueDiscoveryUrl(),
json_encode([
'name' => $this->getName(),
'state_topic' => $this->getQueueStateUrl(),
'device_class' => 'opening'
'device_class' => $deviceClass
]
)
);
......@@ -32,11 +44,6 @@ class RelayState extends SwitchState implements StoreQueueInterface, StoreRrdInt
return $this->getQueueDiscoveryUrl();
}
public function getQueueValue(): string
{
return (parent::getValue() === true) ? 'On' : 'Off';
}
/**
* Dont direct return a boolean value. RRDTool need a int or string
*/
......
<?php
namespace HeatingControl\State;
trait RrdTrait
{
public function getRrdValue(): int
{
return parent::getValue();
}
}
......@@ -9,7 +9,7 @@ use Mosquitto\Client;
*/
class SwitchState extends State implements StoreQueueInterface
{
use QueueUrls;
use MessageQueueTrait;
const SENSOR_PREFIX = 'homeassistant/switch/';
const ECO_KEY = 'eco';
......@@ -29,9 +29,4 @@ class SwitchState extends State implements StoreQueueInterface
return $this->getQueueDiscoveryUrl();
}
public function getQueueValue(): string
{
return (parent::getValue() === true) ? 'On' : 'Off';
}
}
......@@ -9,35 +9,27 @@ use Mosquitto\Client;
*/
class TemperatureSensorState extends State implements StoreRrdInterface, StoreQueueInterface
{
use QueueUrls;
use MessageQueueTrait, RrdTrait;
const SENSOR_PREFIX = 'homeassistant/sensor/';
public function publishQueueDiscovery(Client $client): string
{
$discoveryJson = json_encode(
[
'name' => $this->getName(),
'device_class' => 'temperature',
'state_topic' => $this->getQueueStateUrl(),
'unit_of_measurement' => '°C'
]
);
$client->publish(
$this->getQueueDiscoveryUrl(),
$discoveryJson
json_encode(
[
'name' => $this->getName(),
'device_class' => 'temperature',
'state_topic' => $this->getQueueStateUrl(),
'unit_of_measurement' => '°C'
]
)
);
return $this->getQueueDiscoveryUrl();
}
public function getRrdValue(): int
{
return parent::getValue();
}
public function getQueueValue(): string
{
return parent::getValue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment