Search in sources :

Example 11 with ModbusEndpointThingHandler

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

the class StuderHandler method connectEndpoint.

/**
 * Get a reference to the modbus endpoint
 */
private void connectEndpoint() {
    if (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) ModbusReadRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint) Unit(javax.measure.Unit) StringType(org.openhab.core.library.types.StringType) AsyncModbusFailure(org.openhab.core.io.transport.modbus.AsyncModbusFailure) ModbusRegisterArray(org.openhab.core.io.transport.modbus.ModbusRegisterArray) VSMode(org.openhab.binding.modbus.studer.internal.StuderParser.VSMode) ModeXtender(org.openhab.binding.modbus.studer.internal.StuderParser.ModeXtender) VTType(org.openhab.binding.modbus.studer.internal.StuderParser.VTType) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) ArrayList(java.util.ArrayList) ModbusBitUtilities(org.openhab.core.io.transport.modbus.ModbusBitUtilities) Thing(org.openhab.core.thing.Thing) VTMode(org.openhab.binding.modbus.studer.internal.StuderParser.VTMode) Nullable(org.eclipse.jdt.annotation.Nullable) ModbusCommunicationInterface(org.openhab.core.io.transport.modbus.ModbusCommunicationInterface) ChannelUID(org.openhab.core.thing.ChannelUID) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) DecimalType(org.openhab.core.library.types.DecimalType) QuantityType(org.openhab.core.library.types.QuantityType) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) StuderBindingConstants(org.openhab.binding.modbus.studer.internal.StuderBindingConstants) ThingHandler(org.openhab.core.thing.binding.ThingHandler) State(org.openhab.core.types.State) UnDefType(org.openhab.core.types.UnDefType) Set(java.util.Set) PollTask(org.openhab.core.io.transport.modbus.PollTask) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ModbusReadFunctionCode(org.openhab.core.io.transport.modbus.ModbusReadFunctionCode) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ValueType(org.openhab.core.io.transport.modbus.ModbusConstants.ValueType) Optional(java.util.Optional) Bridge(org.openhab.core.thing.Bridge)

Example 12 with ModbusEndpointThingHandler

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

the class StuderHandler 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) 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 13 with ModbusEndpointThingHandler

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

the class StiebelEltronHandler method startUp.

/*
     * This method starts the operation of this handler Connect to the slave bridge
     * Start the periodic polling1
     */
private void startUp() {
    if (comms != null) {
        return;
    }
    ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
    if (slaveEndpointThingHandler == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Bridge is offline");
        return;
    }
    try {
        slaveId = slaveEndpointThingHandler.getSlaveId();
        comms = slaveEndpointThingHandler.getCommunicationInterface();
    } catch (EndpointNotInitializedException e) {
    // this will be handled below as endpoint remains 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;
    }
    if (config == null) {
        logger.debug("Invalid comms/config/manager ref for stiebel eltron handler");
        return;
    }
    if (systemInformationPoller == null) {
        AbstractBasePoller poller = new AbstractBasePoller() {

            @Override
            protected void handlePolledData(ModbusRegisterArray registers) {
                handlePolledSystemInformationData(registers);
            }
        };
        poller.registerPollTask(500, 36, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
        systemInformationPoller = poller;
    }
    if (energyPoller == null) {
        AbstractBasePoller poller = new AbstractBasePoller() {

            @Override
            protected void handlePolledData(ModbusRegisterArray registers) {
                handlePolledEnergyData(registers);
            }
        };
        poller.registerPollTask(3500, 16, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
        energyPoller = poller;
    }
    if (systemStatePoller == null) {
        AbstractBasePoller poller = new AbstractBasePoller() {

            @Override
            protected void handlePolledData(ModbusRegisterArray registers) {
                handlePolledSystemStateData(registers);
            }
        };
        poller.registerPollTask(2500, 2, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
        systemStatePoller = poller;
    }
    if (systemParameterPoller == null) {
        AbstractBasePoller poller = new AbstractBasePoller() {

            @Override
            protected void handlePolledData(ModbusRegisterArray registers) {
                handlePolledSystemParameterData(registers);
            }
        };
        poller.registerPollTask(1500, 11, ModbusReadFunctionCode.READ_MULTIPLE_REGISTERS);
        systemParameterPoller = poller;
    }
    updateStatus(ThingStatus.UNKNOWN);
}
Also used : ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) ModbusReadRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint) OpenClosedType(org.openhab.core.library.types.OpenClosedType) Unit(javax.measure.Unit) AsyncModbusFailure(org.openhab.core.io.transport.modbus.AsyncModbusFailure) ModbusRegisterArray(org.openhab.core.io.transport.modbus.ModbusRegisterArray) ModbusWriteRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusWriteRequestBlueprint) LoggerFactory(org.slf4j.LoggerFactory) SystemInformationBlock(org.openhab.binding.modbus.stiebeleltron.internal.dto.SystemInformationBlock) StiebelEltronBindingConstants(org.openhab.binding.modbus.stiebeleltron.internal.StiebelEltronBindingConstants) CELSIUS(org.openhab.core.library.unit.SIUnits.CELSIUS) SystemStateBlockParser(org.openhab.binding.modbus.stiebeleltron.internal.parser.SystemStateBlockParser) ModbusWriteRegisterRequestBlueprint(org.openhab.core.io.transport.modbus.ModbusWriteRegisterRequestBlueprint) 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) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) SystemParameterBlockParser(org.openhab.binding.modbus.stiebeleltron.internal.parser.SystemParameterBlockParser) EnergyBlock(org.openhab.binding.modbus.stiebeleltron.internal.dto.EnergyBlock) DecimalType(org.openhab.core.library.types.DecimalType) Units(org.openhab.core.library.unit.Units) EndpointNotInitializedException(org.openhab.binding.modbus.handler.EndpointNotInitializedException) StiebelEltronConfiguration(org.openhab.binding.modbus.stiebeleltron.internal.StiebelEltronConfiguration) SystemParameterBlock(org.openhab.binding.modbus.stiebeleltron.internal.dto.SystemParameterBlock) QuantityType(org.openhab.core.library.types.QuantityType) 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) State(org.openhab.core.types.State) RefreshType(org.openhab.core.types.RefreshType) PollTask(org.openhab.core.io.transport.modbus.PollTask) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ModbusReadFunctionCode(org.openhab.core.io.transport.modbus.ModbusReadFunctionCode) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) SystemInfromationBlockParser(org.openhab.binding.modbus.stiebeleltron.internal.parser.SystemInfromationBlockParser) ModbusEndpointThingHandler(org.openhab.binding.modbus.handler.ModbusEndpointThingHandler) EnergyBlockParser(org.openhab.binding.modbus.stiebeleltron.internal.parser.EnergyBlockParser) Optional(java.util.Optional) SystemStateBlock(org.openhab.binding.modbus.stiebeleltron.internal.dto.SystemStateBlock) Bridge(org.openhab.core.thing.Bridge) ModbusRegisterArray(org.openhab.core.io.transport.modbus.ModbusRegisterArray) EndpointNotInitializedException(org.openhab.binding.modbus.handler.EndpointNotInitializedException)

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