Search in sources :

Example 1 with ModbusEndpointThingHandler

use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.

the class E3DCThingHandler method connectEndpoint.

/**
 * Get a reference to the modbus endpoint
 */
@Nullable
private ModbusCommunicationInterface connectEndpoint() {
    if (comms != null) {
        return comms;
    }
    ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
    if (slaveEndpointThingHandler == null) {
        @SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' is offline", label));
        return null;
    }
    try {
        slaveId = slaveEndpointThingHandler.getSlaveId();
        comms = slaveEndpointThingHandler.getCommunicationInterface();
    } catch (EndpointNotInitializedException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, String.format("Slave Endpoint not initialized"));
        return null;
    }
    if (comms == null) {
        @SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' not completely initialized", label));
        return null;
    } else {
        return comms;
    }
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ModbusReadRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint) StringBlock(org.openhab.binding.modbus.e3dc.internal.dto.StringBlock) DataType(org.openhab.binding.modbus.e3dc.internal.modbus.Data.DataType) AsyncModbusFailure(org.openhab.core.io.transport.modbus.AsyncModbusFailure) E3DCModbusConstans(org.openhab.binding.modbus.e3dc.internal.modbus.E3DCModbusConstans) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) E3DCBindingConstants(org.openhab.binding.modbus.e3dc.internal.E3DCBindingConstants) Thing(org.openhab.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) ModbusCommunicationInterface(org.openhab.core.io.transport.modbus.ModbusCommunicationInterface) ChannelUID(org.openhab.core.thing.ChannelUID) EndpointNotInitializedException(org.openhab.binding.modbus.handler.EndpointNotInitializedException) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) ThingHandler(org.openhab.core.thing.binding.ThingHandler) EmergencyBlock(org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock) PollTask(org.openhab.core.io.transport.modbus.PollTask) ModbusReadFunctionCode(org.openhab.core.io.transport.modbus.ModbusReadFunctionCode) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) PowerBlock(org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Parser(org.openhab.binding.modbus.e3dc.internal.modbus.Parser) AsyncModbusReadResult(org.openhab.core.io.transport.modbus.AsyncModbusReadResult) Optional(java.util.Optional) BaseBridgeHandler(org.openhab.core.thing.binding.BaseBridgeHandler) InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) E3DCConfiguration(org.openhab.binding.modbus.e3dc.internal.E3DCConfiguration) Bridge(org.openhab.core.thing.Bridge) EndpointNotInitializedException(org.openhab.binding.modbus.handler.EndpointNotInitializedException) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with ModbusEndpointThingHandler

use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.

the class E3DCThingHandler method getEndpointThingHandler.

/**
 * Get the endpoint handler from the bridge this handler is connected to
 * Checks that we're connected to the right type of bridge
 *
 * @return the endpoint handler or null if the bridge does not exist
 */
@Nullable
private ModbusEndpointThingHandler getEndpointThingHandler() {
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Bridge is null");
        return null;
    }
    if (bridge.getStatus() != ThingStatus.ONLINE) {
        logger.debug("Bridge is not online");
        return null;
    }
    ThingHandler handler = bridge.getHandler();
    if (handler == null) {
        logger.debug("Bridge handler is null");
        return null;
    }
    if (handler instanceof ModbusEndpointThingHandler) {
        ModbusEndpointThingHandler slaveEndpoint = (ModbusEndpointThingHandler) handler;
        return slaveEndpoint;
    } else {
        logger.debug("Unexpected bridge handler: {}", handler);
        return null;
    }
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ThingHandler(org.openhab.core.thing.binding.ThingHandler) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) Bridge(org.openhab.core.thing.Bridge) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with ModbusEndpointThingHandler

use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.

the class StiebelEltronHandler method getEndpointThingHandler.

/**
 * Get the endpoint handler from the bridge this handler is connected to Checks
 * that we're connected to the right type of bridge
 *
 * @return the endpoint handler or null if the bridge does not exist
 */
@Nullable
private ModbusEndpointThingHandler getEndpointThingHandler() {
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Bridge is null");
        return null;
    }
    if (bridge.getStatus() != ThingStatus.ONLINE) {
        logger.debug("Bridge is not online");
        return null;
    }
    ThingHandler handler = bridge.getHandler();
    if (handler == null) {
        logger.debug("Bridge handler is null");
        return null;
    }
    if (handler instanceof ModbusEndpointThingHandler) {
        ModbusEndpointThingHandler slaveEndpoint = (ModbusEndpointThingHandler) handler;
        return slaveEndpoint;
    } else {
        throw new IllegalStateException("Unexpected bridge handler: " + handler.toString());
    }
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ThingHandler(org.openhab.core.thing.binding.ThingHandler) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) Bridge(org.openhab.core.thing.Bridge) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with ModbusEndpointThingHandler

use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.

the class HeliosEasyControlsHandler method getEndpointThingHandler.

/**
 * Get the endpoint handler from the bridge this handler is connected to
 * Checks that we're connected to the right type of bridge
 *
 * @return the endpoint handler or null if the bridge does not exist
 */
@Nullable
private ModbusEndpointThingHandler getEndpointThingHandler() {
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Bridge is null");
        return null;
    }
    if (bridge.getStatus() != ThingStatus.ONLINE) {
        logger.debug("Bridge is not online");
        return null;
    }
    ThingHandler handler = bridge.getHandler();
    if (handler == null) {
        logger.debug("Bridge handler is null");
        return null;
    }
    if (handler instanceof ModbusEndpointThingHandler) {
        return (ModbusEndpointThingHandler) handler;
    } else {
        logger.debug("Unexpected bridge handler: {}", handler);
        return null;
    }
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ThingHandler(org.openhab.core.thing.binding.ThingHandler) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) Bridge(org.openhab.core.thing.Bridge) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with ModbusEndpointThingHandler

use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.

the class HeliosEasyControlsHandler method connectEndpoint.

/**
 * Get a reference to the modbus endpoint
 */
private void connectEndpoint() {
    if (this.comms != null) {
        return;
    }
    ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
    if (slaveEndpointThingHandler == null) {
        @SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' is offline", label));
        logger.debug("No bridge handler available -- aborting init for {}", label);
        return;
    }
    comms = slaveEndpointThingHandler.getCommunicationInterface();
    if (comms == null) {
        @SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' not completely initialized", label));
        logger.debug("Bridge not initialized fully (no endpoint) -- aborting init for {}", this);
        return;
    }
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ScheduledFuture(java.util.concurrent.ScheduledFuture) TypeToken(com.google.gson.reflect.TypeToken) StringType(org.openhab.core.library.types.StringType) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Nullable(org.eclipse.jdt.annotation.Nullable) Gson(com.google.gson.Gson) Map(java.util.Map) ModbusCommunicationInterface(org.openhab.core.io.transport.modbus.ModbusCommunicationInterface) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ModbusReadFunctionCode(org.openhab.core.io.transport.modbus.ModbusReadFunctionCode) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) Channel(org.openhab.core.thing.Channel) List(java.util.List) Type(java.lang.reflect.Type) Optional(java.util.Optional) SIUnits(org.openhab.core.library.unit.SIUnits) ModbusReadRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint) ModbusRegisterArray(org.openhab.core.io.transport.modbus.ModbusRegisterArray) ThingHandlerService(org.openhab.core.thing.binding.ThingHandlerService) ArrayList(java.util.ArrayList) ModbusBitUtilities(org.openhab.core.io.transport.modbus.ModbusBitUtilities) ModbusWriteRegisterRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusWriteRegisterRequestBlueprint) Thing(org.openhab.core.thing.Thing) ChannelUID(org.openhab.core.thing.ChannelUID) DecimalType(org.openhab.core.library.types.DecimalType) Units(org.openhab.core.library.unit.Units) QuantityType(org.openhab.core.library.types.QuantityType) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) ThingHandler(org.openhab.core.thing.binding.ThingHandler) State(org.openhab.core.types.State) RefreshType(org.openhab.core.types.RefreshType) IOException(java.io.IOException) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) InputStreamReader(java.io.InputStreamReader) TimeUnit(java.util.concurrent.TimeUnit) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ModbusSlaveEndpoint(org.openhab.core.io.transport.modbus.endpoint.ModbusSlaveEndpoint) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) Bridge(org.openhab.core.thing.Bridge)

Aggregations

ModbusEndpointThingHandler (org.openhab.binding.modbus.handler.ModbusEndpointThingHandler)13 Bridge (org.openhab.core.thing.Bridge)11 Nullable (org.eclipse.jdt.annotation.Nullable)10 ThingHandler (org.openhab.core.thing.binding.ThingHandler)10 BaseThingHandler (org.openhab.core.thing.binding.BaseThingHandler)8 ModbusReadRequestBlueprint (org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint)6 Optional (java.util.Optional)5 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)5 ModbusCommunicationInterface (org.openhab.core.io.transport.modbus.ModbusCommunicationInterface)5 ModbusReadFunctionCode (org.openhab.core.io.transport.modbus.ModbusReadFunctionCode)5 ChannelUID (org.openhab.core.thing.ChannelUID)5 Thing (org.openhab.core.thing.Thing)5 ThingStatus (org.openhab.core.thing.ThingStatus)5 ThingStatusDetail (org.openhab.core.thing.ThingStatusDetail)5 Command (org.openhab.core.types.Command)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 EndpointNotInitializedException (org.openhab.binding.modbus.handler.EndpointNotInitializedException)4 ArrayList (java.util.ArrayList)3 Unit (javax.measure.Unit)3